Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM childNodes Property

XML DOM childNodes Property


Node Object Reference Node object


Definition and Usage

The childNodes property returns a NodeList of the child nodes of the specified node.

Syntax

nodeObject.childNodes


Tips and Notes

**Tip:** Use the length property of the NodeList to count the number of nodes in a 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" Load into xmlDoc, and display 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

"


"

)

;

document

.

write

(

"

(nodetype:

"

x

[

i

]

.

nodeType

"

)

"

)

;

}

Output in IE:

Nodename: xml (nodetype: 7)

Nodename: #comment (nodetype: 8)

Nodename: bookstore (nodetype: 1)

Output in Mozilla (Firefox):

Nodename: #comment (nodetype: 8)

Nodename: bookstore (nodetype: 1)

Try it »


Try it Demos

Display all child nodes of all elements in the XML document


Node Object Reference Node object