METHOD:  Element::removeAttributeNode


The removeAttributeNode method removes the specified attribute from the element, returning the removed Attr object. If the removed attribute has a default value, it is immediately replaced by it.

In the following example using the 'albums.xml' file the 'category' attribute is removed from the last 'Album' element. The code then displays the names of the remaining attributes.

   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   <Album ref="CD720" category="Pop">
      <title>Come On Over</title>
      <artist>Shania Twain</artist>
   <Album ref="CD024" category="Country">
      <title>Red Dirt Girl</title>
      <artist>Emmylou Harris</artist>

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

elem = xml_doc.documentElement.lastChild;
attr = elem.getAttributeNode("category");
attr = elem.removeAttributeNode(attr);
atts = elem.attributes;
n_atts = atts.length;
for (i = 0; i < n_atts; i++)
   document.write(atts[i].name + "<br>");


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