To illustrate the Element object, the following code uses the getElementsByTagName method to get all the elements in the 'staff.xml' file, and then iterates through the resulting NodeList collection displaying the tagName of each.
XML: <staff> <employee ssn="123456" pay="3"> <f_name>John</f_name> <l_name>Sullivan</l_name> </employee> <employee ssn="987654" pay="2"> <f_name>Mary</f_name> <l_name>Lopez</l_name> </employee> </staff>
Code (VBScript): Set objXMLDoc = CreateObject("Microsoft.XMLDOM") objXMLDoc.async = False objXMLDoc.load("staff.xml") Set NodeList = objXMLDoc.getElementsByTagName("*") For Each Elem In NodeList document.write(Elem.tagName & "<br>") Next
Output: staffemployeef_namel_name employeef_namel_name
An Element is also a Node object, and so inherits various properties and methods from it. For details of the values returned by the nodeName, nodeType and nodeValue properties for an Element, see the Node object.