PDA

View Full Version : XML nodeValue issue


Wand3r3r
03-30-2004, 08:10 PM
i am using JavaScript to parse an XML document. When I try to get the nodeValue i get null.
------test.xml-----
<Tests>
<Test>
<Test1>HELLO</Test1>
<Test2>WORLD</Test2>
</Test>
</Tests>
------main.htm------
var x = xmlDoc.getElementsByTagname("Test");
for (i=0; i < x.length; i++)
{
document.writeln(x[i].nodeName+"<br>");
for(j=0; j < x[i].childNodes.length; j++)
{
document.writeln("Name = "+x[i].childNodes[j].nodeName+"<br>");
document.writeln("Value= "+x[i].childNodes[j].nodeValue+"<br>");
document.writeln("Type= "+x[i].childNodes[j].nodeType+"<br>");
}
}
------output------
Test
Name = Test1
Value = null
Type = 1
Name = Test2
Value = null
Type = 1
------end------

Also where can I look up what the values for nodeType are.

Thank you,

Mike

liorean
03-30-2004, 08:28 PM
The DOM specs can be found at <http://www.w3.org/DOM/DOMTR>.

The parts you are interested in are:
Node - <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247>
Element: Node - <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-745549614>
CharacterData : Node<http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-FF21A306>
Text : Characterdata - <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1312295772>