W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2008

RE: Should Attr nodes store their values in a child text node?

From: Kartikaya Gupta <kagupta@rim.com>
Date: Thu, 10 Jan 2008 17:40:27 -0500
Message-ID: <24BE9C481C439C48831EB9E52639B9B60A8D47C7@XCH42YKF.rim.net>
To: <www-dom@w3.org>

I'm pretty sure that what Firefox/Safari do here is the correct
behavior. In all cases, the value of an attribute should be present as
one or more children of the Attr node.

In your message, you said "With .value available on attribute nodes, it
doesn't seem like .firstChild.nodeValue is even needed for value
retrieval." This is true, but not the whole story. The value of an Attr
node can be composed of both text and entity references, for example.
This means the Attr node would have multiple children. In this case, the
.value would combine all the children and return a "normalized" value.
In such a case, .firstChild.nodeValue would not be the same as .value.

Adding children to the Attr node should, in turn, reflect the change
back to the .value of the attribute. There are (I believe) tests in the
DOM test suite (http://www.w3.org/DOM/Test/) that specifically test for
this behavior.

Kartikaya Gupta

-----Original Message-----
From: www-dom-request@w3.org [mailto:www-dom-request@w3.org] On Behalf
Of Michael A. Puls II
Sent: Thursday, January 10, 2008 4:44 PM
To: www-dom@w3.org
Subject: Should Attr nodes store their values in a child text node?


var test = document.createAttribute("foo");
test.value = "bar";

Firefox and Safari:
test.childNodes is present.
test.childNodes.length is 1.
test.firstChild is present.
test.firstChild.nodeValue returns "bar".

IE:
test.childNodes is null
test.firstChild is null

Opera:
test.childNodes is present.
test.childNodes.length is 0.
test.firstChild is null.


Firefox and Safari seem to create and append a text node to the
attribute node for storing the value, which makes firstChild and
nodeValue etc. available.

In Opera, a text node is not created, or is created and only used
internally and not revealed to public JS.

This causes a problem for Opera at < http://www.betfair.com/ > under
Games -> X-Blackjack -> turbo.

The problem is (besides Opera being tagged as IE because the site
checks for document.all and Opera reveals document.all) that the site
actually makes use of .firstChild.nodeValue on attributes and the site
breaks in Opera.

I can only find one reason why Firefox and Safari might do this. Under
 < http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-221662474 >, it
says "On setting, this creates a Text node ".

Does that part in the spec really mean what Firefox and Safari do? Is
what they do implied by Attr inheriting from Node? What is the correct
behavior here?

With .value available on attribute nodes, it doesn't seem like
..firstChild.nodeValue is even needed for value retrieval.

To make that site work in Opera 9.5, I have to use UserJS like this:

document.all = undefined;
Attr.prototype.__defineGetter__("firstChild", function() {
    return this.ownerDocument.createTextNode(this.value);
});

What should Opera do here?

Thanks

-- 
Michael



---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.
Received on Thursday, 10 January 2008 22:40:51 GMT

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