Easy Tutorial
❮ Met Cdata Appenddata Met Nodemap Getnameditem ❯

XML DOM childNodes Property



Definition and Usage

The childNodes property returns a node list of child nodes of the document.

Syntax


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 it and extract the values you need!


Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and displays 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:

Output Mozilla (Firefox):


Try It Demos

Display all child nodes of all elements in the XML document


❮ Met Cdata Appenddata Met Nodemap Getnameditem ❯