Condividi tramite


selectSingleNode Method

 

Applies the specified pattern-matching operation to this node's context and returns the first matching node.

JScript Syntax

var objXMLDOMNode = oXMLDOMNode.selectSingleNode(queryString);  

Parameters

queryString
A string specifying an XPath expression.

Return Value

An object. Returns the first node that matches the given pattern-matching operation. If no nodes match the expression, returns a null value.

Example

The following script example creates an IXMLDOMNode object and sets it to the first instance of an AUTHOR node with a BOOK parent. It then displays the text of the node.

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 {  
   xmlDoc.setProperty("SelectionLanguage", "XPath");  
   currNode = xmlDoc.selectSingleNode("//book/author");  
   WScript.Echo(currNode.text);  
}  
  

Output

Gambardella, Matthew

C/C++ Syntax

HRESULT selectSingleNode(  
    BSTR queryString,  
    IXMLDOMNode **resultNode);  

Parameters

queryString[in]
A string specifying an XPath expression.

resultNode[out, retval]
The first node that is selected by the given pattern-matching operation. If no nodes match the expression, returns a null value.

Return Values

S_OK
The value returned if successful.

S_FALSE
The value returned if there is no match.

E_INVALIDARG
The value returned if the resultNode parameter is Null.

Remarks

The selectSingleNode method is similar to the selectNodes method, but returns only the first matching node rather than the list of all matching nodes.

This member is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

Versioning

Implemented in: MSXML 3.0 and MSXML6.0

See Also

Using XSLT with the DOM or SAX
selectNodes Method
setProperty Method1
IXMLDOMAttribute
IXMLDOMCDATASection
IXMLDOMCharacterData
IXMLDOMComment
IXMLDOMDocument-DOMDocument
IXMLDOMDocumentFragment
IXMLDOMDocumentType
IXMLDOMElement
IXMLDOMEntity
IXMLDOMEntityReference
IXMLDOMNode
IXMLDOMNotation
IXMLDOMProcessingInstruction
IXMLDOMText