dictionary - I am trying to read a .strings file in plist version. I have <key> and <string>. I am not sure how to read these inputs in my javascript code. -


i have javascript code type string , find expected in predictive cell , tap on it. simple , working fine. have given plist data not sure how read , use in code.

here example of plist provided me:

<plist version="1.0"> <dict>     <key>animal</key>     <string>cat | dog | chicken | cow</string>     <key>fruits</key>     <string>apple | cherries | kiwi</string> </dict> </plist> 

so first how read each section? understand when type cat, expected result animal according plist. question how following:

i want read , assign value used later need read , assign in array

example:

var inputstringarray = ["cat","dog","chicken","cow"]; var expectedinput = "animal";  

the "plist" format xml can parse plist other xml in javascript using domparser:

// code goes here    var pliststring = '<plist version="1.0"><dict><key>animal</key><string>cat | dog | chicken | cow</string><key>fruits</key><string>apple | cherries | kiwi</string></dict></plist>';    var parser = new domparser()  var xmldoc = parser.parsefromstring(pliststring, "text/xml");    var dictel = xmldoc.getelementsbytagname('dict')[0];  var keyandvalues = dictel.childnodes;    for(var = 0; < keyandvalues.length; i++) {    var el  = keyandvalues[i];    console.log(el.nodename, '-', el.textcontent);  }

you create domparser , parse plist parsefromstring() method.

the object xmldoc contains dom parsed xml , can navigate evert node need. in example above loop on key/value objects inside <dict> element , print them. running code above, should see in console following lines:

key - animal string - cat | dog | chicken | cow key - fruits string - apple | cherries | kiwi 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -