Latest web development tutorials

XML DOM childNodes property

Node Object Reference Node objects

Definition and Usage

ChildNodes property returns a list of the specified node's child nodes.

grammar

nodeObject.childNodes


Tips and Notes

Tip: Use thelength attribute node list of a node to calculate the number of nodes in the list. When you already know the length of the node list, you can easily loop through this list, and extract value you need!


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and display the sub node of the XML document:

Examples

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.childNodes;
for (i=0;i<x.length;i++)
{
document.write("Nodename: " + x[i].nodeName);
document.write(" (nodetype: " + x[i].nodeType + ")
");
}

Output IE:

Nodename: xml (nodetype: 7)
Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)

Output Mozilla (Firefox):

Nodename: #comment (nodetype: 8)
Nodename: bookstore (nodetype: 1)

try it"

Try Demos

Display XML document all the child nodes of all elements


Node Object Reference Node objects