XML DOM » Element » getAttributeNode

Syntax:
element.getAttributeNode(name)

This method returns an object of the specified name.

The getAttributeNode method returns an Attr object of the specified name, as opposed to just the string value returned by the getAttribute method. If the named attribute connot be found on this element, this method returns null.

Examples

Code:
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>

VBScript:

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

Set LastState = objXMLDoc.documentElement.lastChild
Set RefAttr = LastState.getAttributeNode("ref")
document.write("Name: " & RefAttr.name)
document.write("<br>Value: " & RefAttr.value)
Output:
Name: ref
Value: IA
Explanation:

The following example uses the 'states.xml' file and gets an Attr object of 'ref' attribute of the last 'State' element. The code then displays its name and value.

Language(s): VBScript XML

See Also: