Microsoft XML SDK 2.6 - XML Reference

selectSingleNode Method

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

objXMLDOMNode = oXMLDOMNode.selectSingleNode(patternString)

Parameters

patternString
String specifying the XSL or XPath query that is to be applied to the context defined by this node. Whether an XSL or XPath query is used is determined by the value of the SelectionLanguage property. By default, the expression is an XSL pattern query. The SelectionLanguage property can be set with the SetProperty method.

Return Value

Object. Returns the first node that matches the XSL or XPath query. If no nodes match the query, it returns Null.

Remarks

For a complete description of XSL Syntax, see XSL Pattern Syntax.

For a complete description of XPath syntax, see XPath Syntax.

The selectSingleNode method is much like 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 W3C DOM.

Example

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

Dim xmlDoc
Dim currNode
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\books.xml")
Set currNode = xmlDoc.documentElement.selectSingleNode("BOOK/AUTHOR")
MsgBox currNode.text

See Also

Using the XSLT Processor

Applies To: XMLDOMAttribute Object | XMLDOMCDATASection Object | XMLDOMCharacterData Object | XMLDOMComment Object | DOMDocument Object | XMLDOMDocumentFragment Object | XMLDOMDocumentType Object | XMLDOMElement Object | XMLDOMEntity Object | XMLDOMEntityReference Object | XMLDOMNode Object | XMLDOMNotation Object | XMLDOMProcessingInstruction Object | XMLDOMText Object | XTLRuntime Object