This is a read-only property containing a node list of all children for those elements that can have them.
The childNodes property is a read-only property containing a node list of all children for those elements that can have them. It returns a NodeList for the following valid node types:
XML:
<States>
<State
ref="FL">
<name>Florida</name>
<capital>Tallahassee</capital>
</State>
<State
ref="IA">
<name>Iowa</name>
<capital>Des Moines</capital>
</State>
</States>
VBScript:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")
Dim objChildNodes, strNode
Set objChildNodes = objXMLDoc.documentElement.childNodes<State>
For Each strNode In objChildNodes
document.write(strNode.nodeName & "<br>")
Next
State
State
This example loads the 'states.xml' file and gets the childNodes of the root element. If we then iterate through the child nodes, displaying their node names, you will see that they are the two <State> tags of our XML file.
As you might have guessed, each of the child nodes in the above example has its own child nodes.
Set objChildNodes = objXMLDoc.documentElement.childNodes.item(0).childNodes<State>
For Each strNode In objChildNodes
document.write(strNode.xml & "<br>")
Next
Florida
Tallahassee
To refer to a random, individual node in the childNodes collection you use the item method of the NodeList object with the appropriate index. So, if we want to get the child nodes of the first child node of the root element, the code would look like this example. Now you can loop through the child nodes representing the elements of the first <State> tag, and display the xml for those nodes: