when i try to access child nodes i can , but i can’t access their value it says null
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","obj.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x=xmlDoc.getElementsByTagName("Objnode")[0].childNodes;
y=xmlDoc.getElementsByTagName("Objnode")[0].firstChild;
for (i=0;i<x.length;i++)
{
if (y.nodeType==1)
{//Process only element nodes (type 1)
document.write(y.nodeName + "<br>"); change it to y.nodeValue it says null!
}
y=y.nextSibling;
}
my xml is like
<Objnode>
<Object1>something</Object1>
<Object2>something</Object2>
</Objnode>
above code works but the line
document.write(y.nodeName + "<br>");
when changed it to y.nodeValue it says null!
Actually
nodeType 1is anHTML element, i.e. div, span etcand an element doesn’t has anynodeValueinstead it could contain child nodes and remember that any text inside anelementis also a node (text node). Look at this exampleHTML
JS
So, in your example
y.nodeValueis null.DEMO.