METHOD:  Object::hasChildNodes

Object  Attr   CDATASection   CharacterData   Comment   Document   DocumentFragment   DocumentType   Entity   EntityReference   Node   Notation   ProcessingInstruction   Text
 
Object.hasChildNodes( )

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

In the following 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.

XML:
<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

Code (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



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information