XML DOM » Node » selectNodes

Compability: Internet Explorer

Syntax:
node.selectNodes(patternString)

This method creates a NodeList of all matching descendant nodes returned by the specified pattern-matching operation.

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.

Examples

Code:
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>

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
Explanation:

This 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.

Language(s): VBScript XML