tinfanide Posted October 22, 2011 Share Posted October 22, 2011 JS: function parseXML(method,xml,async){if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); xmlhttp.open(method,xml,async); xmlhttp.send(); }else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") ; xmlhttp.async=async; xmlhttp.load(xml); }xmlDoc = xmlhttp.responseXML;}parseXML("GET","answers.xml",false);alert(xmlDoc.getElementsByTagName("ans")[0].childNodes[0].nodeValue[0]); The XML: <?xml version="1.0" encoding="utf-8"?><database> <ans>a</ans> <ans>b</ans></database> I want to ask if there is a IE7, 8, 9 solution inXML parsingI mean for childNodes As in IE9I get the result of "a" which is right But in IE7, 8The result is "undefined" in the IE9 Developer Tool Link to comment Share on other sites More sharing options...
Ingolme Posted October 22, 2011 Share Posted October 22, 2011 Nodevalue doesn't need a [0] on it..nodeValue[0] Link to comment Share on other sites More sharing options...
tinfanide Posted October 22, 2011 Author Share Posted October 22, 2011 Oh, I see. That simple.Thanks! Link to comment Share on other sites More sharing options...
boen_robot Posted October 22, 2011 Share Posted October 22, 2011 I want to ask if there is a IE7, 8, 9 solutionThe cross-browser way to use childNodes is to eliminate all empty whitespace nodes from the XML file. That way, IE9 takes the first node, which is the element, and IE9- take the first non-empty node, which happens to also be the first node according to IE9 and other browsers. Link to comment Share on other sites More sharing options...
tinfanide Posted October 22, 2011 Author Share Posted October 22, 2011 so to IE all xmlDoc.getElementsByTagName("ans")[0].childNodes[0].nodeValue[0] It means a in the XML file? Link to comment Share on other sites More sharing options...
Ingolme Posted October 23, 2011 Share Posted October 23, 2011 If you have that [0] at the end then it's not going to work (or it might just return the first letter of the string) since nodeValue isn't an array. The expression does "mean" that, it just returns that data from the data tree. Link to comment Share on other sites More sharing options...
tinfanide Posted October 23, 2011 Author Share Posted October 23, 2011 I see. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.