XML DOM childNodesProperty
Document object
Definition and Usage
The childNodes property returns the node list of the document's child nodes.
Syntax
documentObject.childNodes
Tips and notes
Tip:Use the length property of the NodeList to determine the number of nodes in the node list. Once you know the length of the node list, you can easily loop through this node list and extract the values you need!
Example
The following code snippet usesloadXMLDoc()put "books.xmlLoad it into xmlDoc, and display the child nodes of the XML document:
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.childNodes;
for (i=0;i<x.length;i++)
{
document.write("Nodename: " + x[i].nodeName + "<br>");
document.write(" (nodetype: " + x[i].nodeType + ") ");
}
Output IE:
Nodename: xml (nodetype: 7)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
Output Mozilla (Firefox):
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)
Nodename: bookstore (nodetype: 1)
Try it Yourself »
Try the Demos
Display all child nodes of all elements in an XML document
Document objectother extensions