XML DOM » Node » selectSingleNode

Compability: Internet Explorer

Syntax:
node.selectSingleNode(patternString)

This method returns an object for the first descendant node to match the specified pattern.

The one parameter of this method is an XSL pattern query. If no match is made, it returns null. This method is similar to the selectNodes method, but returns only the first node to match the pattern rather than all of them.

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 Node = objXMLDoc.documentElement.selectSingleNode("Word/Spanish")
document.write(Node.text)
Output:
gato
Explanation:

This example loads the 'vocabulary.xml' file and uses the selectSingleNode method get the first 'Spanish' element node. The code then displays its text.

Language(s): VBScript XML