METHOD:  Element::getElementsByTagName


The getElementsByTagName method returns a NodeList of all descendant elements of the specified name. If you supply the three characters "*" as the argument to this method, it returns all descendant elements of whatever name.

In the following example using the 'albums.xml' file the code creates a NodeList of all the 'artist' elements, and then iterates through it displaying the nodeValue of the firstChild of each (the text).

   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   <Album ref="CD720" category="Pop">
      <title>Come On Over</title>
      <artist>Shania Twain</artist>
   <Album ref="CD024" category="Country">
      <title>Red Dirt Girl</title>
      <artist>Emmylou Harris</artist>

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

Set Root = objXMLDoc.documentElement
Set NodeList = Root.getElementsByTagName("artist")
For Each Elem In NodeList
   document.write(Elem.firstChild.nodeValue & "<br>")

The Chieftains
Shania Twain
Emmylou Harris

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