Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
can you help me?
how can i pass an xml data into an array using for loop?
this is my code
JavaScript
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","data/stations_en.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;


var x = xmlDoc.getElementsByTagName("station");


for(var t = 0;t < x.length; t++)
{

    var locations = [
        [x[t].getElementsByTagName("name")[0].childNodes[0].nodeValue],
        [x[t].getElementsByTagName("lattitude")[0].childNodes[0].nodeValue],
        [x[t].getElementsByTagName("longitude")[0].childNodes[0].nodeValue]
   ];
}
document.write(locations[0],locations[1],locations[2]);
Posted
Updated 21-Apr-14 20:14pm
v5
Comments
Sunasara Imdadhusen 22-Apr-14 6:51am    
So, what is your problem?? are you getting any error using above code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900