Jump to content

Ie9- Vs Ie9: Childnodes


tinfanide

Recommended Posts

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

I want to ask if there is a IE7, 8, 9 solution
The 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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...