W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2000

Re: Attribute Insertion behavior

From: <keshlam@us.ibm.com>
Date: Mon, 24 Apr 2000 14:43:39 -0400
To: www-dom@w3.org
Message-ID: <852568CB.0066D4A6.00@D51MTA03.pok.ibm.com>
> Assuming I have an element 'e' and an attribute 'a' named "A" with value
> "old", what is the expected behavior supposed to be in the following
>    e.setAttributeNode(a);
>    a.setValue("new");
>    Attr a2 = e.getAttributeNode("A");
> Is a2's value supposed to equal "new" or "old"


e.setAttributeNode(a) associates Attr node a with Element node e.

a.setValue("new") modifies that node, discarding its previous contents and
replacing them with a single Text node containing the value "new". It does
not change the attribute's owningElement.

When you issue the last line, you are retrieving a reference to the same
Attr node, as modified by the second line.

If you don't want that behavior, clone the attribute before adding it, or
before modifying it, and alter the copy which has not been associated with
the Element.

Joe Kesselman  / IBM Research
Received on Monday, 24 April 2000 14:44:15 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:07 UTC