开发者

parsing xml doc with Javascript

开发者 https://www.devze.com 2023-03-10 13:14 出处:网络
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 won

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

精彩评论

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