XML DOM childNodes property
Definition and Usage
childNodes property returns contain child nodes of the selected node NodeList.
If the selected node has no children, this property returns NodeList containing no nodes.
grammar
Tips and Notes
Tip: To loop through childNodes list, use nextSibling property higher than the use of the parent object childNodes list of efficiency.
Example 1
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and the first <title> element made from the text node "books.xml" in:
Examples
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.write(x.nodeValue);
The code above will output:
try it"
Example 2
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and the first <title> element to obtain the number of child nodes from "books.xml" in:
Examples
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
document.write(x.length);
In Internet Explorer, the code above will output:
In the Mozilla browser, the code above will output:
try it"
Firefox and most other browsers, the empty spaces between the nodes will generate or wrap as text nodes, while Internet Explorer will ignore whitespace text nodes between nodes generated. Thus, in the example above, the output is not the same.
For more information about browser differences, please visit us in our XML DOM tutorial DOM browser section.
Element object