XML DOM » Element » getElementsByTagName

Syntax:
element.getElementsByTagName(name)

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

Examples

Code:
XML:

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

VBScript:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("albums.xml")

Set Root = objXMLDoc.documentElement
Set NodeList = Root.getElementsByTagName("artist")
For Each Elem In NodeList
   response.write(Elem.firstChild.nodeValue "<br>")
Next
Output:
The Chieftains
Shania Twain
Emmylou Harris
Explanation:

In this 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).

Language(s): VBScript XML