NamedNodeMap.getNamedItem(name)
The getNamedItem method returns a Node object for
the specified item, or null if the item does not exist.
The following example loads the 'states.xml' file and uses the getNamedItem method
to create a Node object of the 'ref' attribute of the last
'State' element. It then displays its nodeValue.
XML:
<States>
<State ref="FL" const="27">
<name>Florida</name>
<capital>Tallahassee</capital>
</State>
<State ref="IA" const="29">
<name>Iowa</name>
<capital>Des Moines</capital>
</State>
</States>
Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")
Set objLastChild = objXMLDoc.documentElement.lastChild
Set objAttributes = objLastChild.attributes
Set objRefAttr = objAttributes.getNamedItem("ref")
document.write(objRefAttr.nodeValue)
Output:
IA
|