XML DOM » Node » attributes

Syntax:
node.attributes

This is a read-only property that returns a NamedNodeMap for nodes that can have attributes.

The attributes property contains a list of attributes for any node that can have them. It returns a NamedNodeMap object for Element, Entity and Notation nodes, and null for any other type. The NamedNodeMap can then be accessed to obtain values for those attributes. If a valid nodeType does not have any attributes, then the length of the list is set to zero. The example that follows loads an XML page for CD's. The first child node of the root is a 'CD' tag, and these tags have one attribute: a 'ref' attribute whose value is a reference number for the CD.

<CD ref="CCD142">

Examples

Code:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("CDs.xml")

Dim objNamedNodeMap, intAtt, strAttName
Set objNamedNodeMap =
objXMLDoc.documentElement.firstChild.attributes
For Each intAtt in objNamedNodeMap
   document.write(intAtt.name & "<br>")
Next
Output:
ref
Explanation:

Having loaded the XML file, this code then assigns the attributes of this child node to an NamedNodeMap object, and iterates through them displaying them on the page.

Language(s): VBScript