An XMLDOMNamedNodeMap object is returned by the attributes property. The XMLDOMNamedNodeMap object differs from the node list in that it is a collection of nodes that can also be accessed by name. The following topics discuss how to use the XMLDOMNamedNodeMap object.
Just like the XMLDOMNodeList object, the XMLDOMNamedNodeMap object exposes the length property. This property returns the number of members in the named node map.
As with a node list, you can access members of the named node map by index using the item method. In addition to this method, however, you can also access the members of a named node map name using getNamedItem and getQualifiedItem. The getNamedItem method takes the name of the desired node as a parameter; the getQualifiedItem method takes the name and namespaceURI of the desired node. Each method returns an XMLDOMNode object. The following sample code retrieves the value of the ID attribute on the "elem1" element and assigns that value to the variable "idValue".
idValue = elem1.attributes.getNamedItem("ID").nodeValue
The XMLDOMNamedNodeMap object, like the node list object, also exposes the nextNode property.
There are three methods to manipulate named node maps: setNamedItem, removeNamedItem, and removeQualifiedItem. The setNamedItem method takes an XML node object as a parameter, adding that node to the named node map. If an attribute already exists with the same name as that specified by the nodeName
of the node added, the old attribute is replaced. The following sample code creates a new attribute node with the name "ID" and adds it to the attributes of "elem1."
idAtt = XMLDoc.createAttribute("ID")
elem1.setNamedItem(idAtt)
The removeNamedItem method takes a node name as a parameter, removing the node with that name. The removeQualifiedItem method takes a node name and namespaceURI as its parameters, removing the corresponding attribute.