Possible Duplicate:
how to extract values from an XML document using Javascript
My demo.xml file contain the following data:
<?xml version="1.0"?>
<user>
<details>
<name>abc</name>
<class>xyz</class>
<city>pqr</city>
</details>
<info>
<id>123</id>
<code>456</code>
</info>
</user>
I want to fetch all these data from file demo.xml into my code using Javascript. How can I get this? Any solution? Thanks....
here is an example wich can put you in the right direction:
var request = new XMLHttpRequest();
request.open("GET", "/path/demo.xml", false);
request.send();
var xml = request.responseXML;
var users = xml.getElementsByTagName("user");
for(var i = 0; i < users.length; i++) {
var user = users[i];
var names = user.getElementsByTagName("name");
for(var j = 0; j < names.length; j++) {
alert(names[j].childNodes[0].nodeValue);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With