Microsoft XML SDK 2.6 - XML Reference

hasChildNodes Method

Returns True if this node has children.

boolValue = oXMLDOMNode.hasChildNodes()

Return Value

Boolean. Returns True if this node has children.

Remarks

This method offers a fast way to determine whether a node has children. It always returns False for nodes that, by definition, cannot have children: the XMLDOMCDATASection, XMLDOMComment, XMLDOMNotation, XMLDOMProcessingInstruction, and XMLDOMText nodes.

Example

The following example checks a node to see if it has any child nodes. If it does, it displays the number of child nodes it contains:

Dim xmlDoc
Dim currNode
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\books.xml")
Set currNode = xmlDoc.documentElement.firstChild
If currNode.hasChildNodes Then
  MsgBox currNode.childNodes.length
Else
  MsgBox ("no child nodes")
End If

See Also

Applies To: XMLDOMAttribute Object | XMLDOMCDATASection Object | XMLDOMCharacterData Object | XMLDOMComment Object | DOMDocument Object | XMLDOMDocumentFragment Object | XMLDOMDocumentType Object | XMLDOMElement Object | XMLDOMEntity Object | XMLDOMEntityReference Object | XMLDOMNode Object | XMLDOMNotation Object | XMLDOMProcessingInstruction Object | XMLDOMText Object | XTLRuntime Object