Microsoft XML SDK 2.6 - XML Reference

selectNodes Method (XMLDOMNode)

Applies the specified pattern-matching operation to this node's context and returns the list of matching nodes as an XMLDOMNodeList object.

objXMLDOMNodeList = oXMLDOMNode.selectNodes(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 a collection of nodes selected by an XSL or XPath query. If no nodes are selected, an empty collection is returned.

Remarks

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

For a description of XPath sytax, 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.

The XMLDOMNodeList object is live and immediately reflects changes to the nodes that appear in the list.

This member is an extension of the W3C DOM.

Example

The following VBScript example creates an XMLDOMNodeList object containing the nodes specified by the pattern string (i.e., all of the AUTHOR child nodes with a BOOK parent). It then displays the number of nodes contained in the node list:

Dim xmlDoc
Dim nodeList
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.load("c:\books.xml")
Set objNodeList = xmlDoc.documentElement.selectNodes("BOOK/AUTHOR")
MsgBox objNodeList.length

See Also

Using the XSLT Processor | Using Collections

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