Provides a fast way to determine whether a node has children.
boolValue = oXMLDOMNode.hasChildNodes();
Boolean. Returns True if this node has children.
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.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var currNode; xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode <> 0) { var myErr = xmlDoc.parseError; alert("You have error " + myErr.reason); } else { currNode = xmlDoc.documentElement.firstChild; if (currNode.hasChildNodes()) { alert(currNode.childNodes.length); } else { alert("no child nodes"); } }
boolValue = oXMLDOMNode.hasChildNodes
Boolean. Returns True if this node has children.
The following Microsoft® Visual Basic® 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 As New Msxml2.DOMDocument50 Dim currNode As IXMLDOMNode xmlDoc.async = False xmlDoc.Load ("books.xml") If (xmlDoc.parseError.errorCode <> 0) Then Dim myErr Set myErr = xmlDoc.parseError MsgBox("You have error " & myErr.reason) Else Set currNode = xmlDoc.documentElement.firstChild If currNode.hasChildNodes Then MsgBox currNode.childNodes.length Else MsgBox "no child nodes" End If End If
HRESULT hasChildNodes( VARIANT_BOOL *hasChild);
hasChild
parameter is Null.It always returns False for nodes that, by definition, cannot have children: the IXMLDOMCDATASection
, IXMLDOMComment
, IXMLDOMNotation
, IXMLDOMProcessingInstruction
, and IXMLDOMText
nodes.
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText