开发者

parsing xml doc with Javascript

hey guys.. i was wondering what the best way to go about getting a node from an xml doc into a javascript variable would be? i dont really want to use jquery because i believe that 开发者_运维问答i wont have too.. so far i have:

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","sc2cash.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

but now how i select the nodes? thanks


You can parse the returned XML using DOM manipulators. We'll need more information about the XML returned to be more specific.

xmlDoc=xmlhttp.responseXML;

// For example - get "person" tags if there were any
var people = xmlDoc.getElementsByTagName("person");

// All child nodes under the first person
var children = people[0].childNodes;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜