METHOD:  NamedNodeMap::removeNamedItem

NamedNodeMap.removeNamedItem(name)

The removeNamedItem method removes the specified item from the collection and returns it as a Node object, or returns null if the item does not exist. If the node is an attribute with a default value, it is immediately replaced.

The following example loads the 'states.xml' file and uses the removeNamedItem method to remove the 'const' attribute of the first 'State' element. It then displays the nodeValue of the returned Node, and a statement of the current length of the NamedNodeMap.

XML:
<States>
   <State ref="FL" const="27">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA" const="29">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

Code (JavaScript):
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("states.xml");

element = xml_doc.documentElement.firstChild;
atts = element.attributes;
removed_node = atts.removeNamedItem("const");
document.write(removed_node.nodeValue);
document.write("<br>Number of remaining attributes: " + atts.length);

Output:
27
Number of remaining attributes: 1



Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information