how to get name of a xml tag with js ajax

Ethiggiva

New Member
I have an xml file i am ripping apart with ajax:\[code\]<country name="UK"> <person> <name>daniel</name> <age>25</city> </person> <person> <name>james</name> <age>22</city> </person> <person> <name>brandy</name> <age>16</city> </person> <person> <name>nathan</name> <age>66</city> </person> </country> <country name="france"> <person> <name>paul</name> <age>28</city> </person> <person> <name>pierr</name> <age>22</city> </person> </country>\[/code\]Any my JS look like this:\[code\]<script type="text/javascript">function loadXMLDoc() {xmlhttp=null;xmlhttp=new XMLHttpRequest();xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { xmlDoc=xmlhttp.responseXML; var txt=""; x=xmlDoc.getElementsByTagName("name"); for (i=0;i<x.length;i++) { txt=txt + x.childNodes[0].nodeValue + "<br />"; } document.getElementById("myDivName").innerHTML=txt; //somehow get the country of that person to write here document.getElementById("myDivCountry").innerHTML=txt; } xmlhttp.open("GET","people.xml",true); xmlhttp.send(); }}</script>\[/code\]The JS will print the name of the person, but how to i get the name of the country that person belongs to?this is all example content written for this problem... i didn't right the xml - it's a feed from another location i want to filterthanksdan
 
Back
Top