XML DOM childNodes Property
Definition and Usage
The 'childNodes' property returns a node list of the child nodes of the specified node.
Syntax:
nodeObject.childNodes
Tips and comments
Tip:Use the length property to calculate the number of nodes in a node list. Once you know the length of the node list, you can easily loop through the list and extract the values you need!
Example
In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().
The following code snippet shows the child nodes of this XML document:
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.childNodes
;
for (i=0;i<x.length;i++)
{
document.write("Nodename: " + x[i].nodeName)
document.write(" (nodetype: " + x[i].nodeType + ")<br />")
Output from IE:
Nodename: xml (nodetype: 7) Nodename: #comment (nodetype: 8) Nodename: bookstore (nodetype: 1)
Output from Mozilla (Firefox):
Nodename: #comment (nodetype: 8) Nodename: bookstore (nodetype: 1)