METHOD:  Node::selectNodes

This method is a Microsoft extension to the W3C DOM.

Node.selectNodes(patternString)

The selectNodes method creates a NodeList of all the matching descendant nodes returned by the specified pattern-matching operation. The one parameter of this method is an XSL pattern query. If no match is made, an empty node list is returned. This method is similar to the selectSingleNode method, but returns all nodes that match the pattern rather than just the first encountered.

The following example loads the 'vocabulary.xml' file and uses the selectNodes method to create a collection of all 'English' element nodes. The code then iterates through the collection displaying the text of each.

XML:
<Vocabulary>
   <Word type="noun" level="1">
      <English>cat</English>
      <Spanish>gato</Spanish>
   </Word>
   <Word type="verb" level="1">
      <English>speak</English>
      <Spanish>hablar</Spanish>
   </Word>
   <Word type="adj" level="1">
      <English>big</English>
      <Spanish>grande</Spanish>
   </Word>
</Vocabulary>

Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("vocabulary.xml")

Set NodeList = objXMLDoc.documentElement.selectNodes("Word/English")
For Each Node In NodeList
   document.write(Node.text & "<br>")
Next

Output:
cat
speak
big



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information