XML DOM childNodes eigenschap

Document object reference manual

Definitie en gebruik

childNodes eigenschap kan de NodeList van de onderliggende knooppunten van document retourneren.

语法:

documentObject.childNodes

Tips and comments:

Tip:Use the length property of NodeList to determine the number of nodes in the node list. Once you know the length of the node list, you can easily iterate through the nodes and extract the values you need!

Example

In all examples, we will use the XML file books.xml, as well as the JavaScript function loadXMLDoc().

The following code snippet can display the child nodes of the XML document:

xmlDoc=loadXMLDoc("/example/xdom/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 of IE:

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

Output of Mozilla (Firefox):

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

Document object reference manual