METHOD:  Object::selectSingleNode

This method is a Microsoft extension to the W3C DOM.

Object  Attr   CDATASection   CharacterData   Comment   Document   DocumentFragment   DocumentType   Entity   EntityReference   Node   Notation   ProcessingInstruction   Text
 
Object.selectSingleNode(patternString)

The selectSingleNode method returns a Node 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.

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

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

Output:
gato



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