Manipulating a Named Node Map
You can use the following methods to manipulate named node maps.
- setNamedItem method
The
setNamedItemmethod 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 thenodeNameof the node added, the old attribute is replaced. The following code creates a new attribute node with the nameIDand adds it to the attributes of<elem1>.idAtt = XMLDoc.createAttribute("ID") elem1.attributes.setNamedItem(idAtt) - removeNamedItem method
The
removeNamedItemmethod takes a node name as a parameter, removing the node with that name. - removeQualifiedItem method
The
removeQualifiedItemmethod 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.
