XML DOM » Node » hasChildNodes

Syntax:
node.hasChildNodes

This method is a convenient way to determine whether a node has child nodes, returning true if it has, and false if not.

Examples

Code:
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")

Sub Drill(n)
   document.write(n.nodeName & "<br>")
   If n.hasChildNodes Then
      Set n = n.firstChild
      Drill(n)
   End If
End Sub

Drill(objXMLDoc.documentElement)
Output:
States
State
name
#text
Explanation:

In this example we recursively drill down the DOM tree of the 'states.xml' file through the first child of each node. The nodeName is displayed at each level and the hasChildNodes method used to determine whether to recall the sub.

Language(s): VBScript XML