次の方法で共有


hasChildNodes Method

 

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

JScript Syntax

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.

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  

C/C++ Syntax

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.

Remarks

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

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

See Also

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