Latest web development tutorials

XML DOM childNodes property

Document Object Reference Document Object

Definition and Usage

childNodes attribute returns a list of child nodes of the document.

grammar

documentObject.childNodes


Tips and Notes

Tip: Use NodeList length property to determine the number of nodes in a node list.If you know the length of the node list after you can easily loop through this list of nodes and extract the values ​​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


Document Object Reference Document Object