On Fri, 16 Feb 2001, Jean-Charles DUFOUR wrote:
> Hello,
>
> I need quick help !
>
> How can I suppress an attribute of a DOM Node ?
>
> Here my NODE : <FOO foo_attr="value"/> (it's a DOM Node)
>
> I use Xalan and xsl syntax to find the attribute like this :
> Node foo_attr = Xpath.selectSingleNode(fooDOMNode,
> "attribute::foo_attr");
>
> And the I do :
> fooDOMNode.removeChild(foo_attr);
>
> But this last instruction throws an "org.w3c.dom.DOMException: DOM008 Not
> found"
Attributes aren't actually children. fooDOMNode is an instance of
Element, so the simplest thing to do is:
((Element)fooDOMNode).removeAttribute("foo_attr");
You don't need to do the XPath to get the attribute node. All you need is
the name (though you can use removeAttributeNode to remove the attribute
node directly once you have it).
Ian
--
Ian Roberts, Software Engineer DecisionSoft Ltd.
tel: +44-1865-203192 http://www.decisionsoft.com