How do I convert this piece of XML into a javascript collection? -


i'd convert xml looks this:

<products>    <product>      <name>bill</name>      <id>1</id>      <age>19</age>    </product>    <product>      <name>jim</name>      <id>2</id>      <age>23</age>    </product>    <product>      <name>kathy</name>      <id>3</id>      <age>53</age>    </product> </products> 

into format: name, id, age in collection

like following:

collection = [ 'bill-1-19', 'jim-2-23', 'kathy-3-53', ]; 

i think best way xslt stylesheet outputs right? use help, i've been trying figure out hours now.

here have far:

<!doctype html> <html> <body> <script> if (window.xmlhttprequest)   {   xhttp=new xmlhttprequest();   } else // ie 5/6   {   xhttp=new activexobject("microsoft.xmlhttp");   } xhttp.open("get","after.xml",false); xhttp.send(); xml=xhttp.responsexml;  var products = xml.getelementsbytagname("products"); var arr = []; (var key in products){     var stringval = "";     var nodes = products[key].childnodes;     (var ele in nodes){           if(nodes[ele]){            stringval = stringval + nodes[ele];         }     }     arr.push(stringval); } console.log(arr);  </script> </body> </html> 

not had tested should work imo. iterate xml listing , build string

var products = xml.getelementsbytagname("products"); var arr = []; (var key in products){ var stringval = ""; var nodes = products[key].childnodes; (var ele in nodes){ if(nodes[ele]){ stringval = stringval + nodes[ele]; } } arr.push(stringval); } console.log(arr);

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -