Manipulating a Named Node Map

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Manipulating a Named Node Map

You can use the following methods to manipulate named node maps.

  • setNamedItem method

    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 code creates a new attribute node with the name ID and adds it to the attributes of <elem1>.

    idAtt = XMLDoc.createAttribute("ID")
    elem1.attributes.setNamedItem(idAtt)

  • removeNamedItem method

    The removeNamedItem method takes a node name as a parameter, removing the node with that name.

  • removeQualifiedItem method

    The removeQualifiedItem method takes a node name and namespace URI as its parameters, removing the corresponding attribute.

Alternatively, element nodes also support the setAttribute, setAttributeNode, removeAttribute, and removeAttributeNode methods if you prefer to treat attributes as properties of elements rather than as members of a collection contained by an element.