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
case?
>    e.setAttributeNode(a);
>    a.setValue("new");
>    Attr a2 = e.getAttributeNode("A");
> Is a2's value supposed to equal "new" or "old"

"new".

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:47 GMT