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.

System_CAPS_ICON_note.jpg Note

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

IXMLDOMAttribute
IXMLDOMCDATASection
IXMLDOMCharacterData
IXMLDOMComment
IXMLDOMDocument-DOMDocument
IXMLDOMDocumentFragment
IXMLDOMDocumentType
IXMLDOMElement
IXMLDOMEntity
IXMLDOMEntityReference
IXMLDOMNode
IXMLDOMNotation
IXMLDOMProcessingInstruction
IXMLDOMText

Show: