You can use the following methods to manipulate named node maps.
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)
The removeNamedItem
method takes a node name as a parameter, removing the node with that name.
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.