Element.getElementsByTagName(name)
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).
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>
Code (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
document.write(Elem.firstChild.nodeValue & "<br>")
Next
Output:
The Chieftains Shania Twain Emmylou Harris
|