Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

hasChildNodes Method

Provides a fast way to determine whether a node has children.

boolValue = oXMLDOMNode.hasChildNodes();

Return Value

Boolean. Returns True if this node has children.

Example

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

NoteNote

You can use books.xml to run this sample code.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
var currNode;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   currNode = xmlDoc.documentElement.firstChild;
   if (currNode.hasChildNodes()) {
      WScript.Echo(currNode.childNodes.length);
   } else {
      WScript.Echo("no child nodes");
   }
}

Output

6

HRESULT hasChildNodes(
    VARIANT_BOOL *hasChild);

Parameters

hasChild[out, retval]

Returns True if this node has children.

Return Values

S_OK

The value returned if successful.

S_FALSE

The value returned when there are no children.

E_INVALIDARG

The value returned if the hasChild parameter is Null.

It always returns False for nodes that, by definition, cannot have children: the IXMLDOMCDATASection, IXMLDOMComment, IXMLDOMNotation, IXMLDOMProcessingInstruction, and IXMLDOMText nodes.

Implemented in: MSXML 3.0 and MSXML 6.0

Show:
© 2015 Microsoft