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: Michael A. Puls II <shadow2531@gmail.com>
Date: Fri, 11 Jan 2008 21:54:10 -0500
Message-ID: <6b9c91b20801111854sec08e92n2774620c831359b4@mail.gmail.com>
To: "Kartikaya Gupta" <kagupta@rim.com>
Cc: www-dom@w3.org

On 1/10/08, Kartikaya Gupta <kagupta@rim.com> wrote:
> 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.

Since entity reference nodes don't work in browsers, I tried with PHP.


<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css"
<!DOCTYPE example [<!ENTITY magic "zam">]>
    <note>You should see zip&magic;bam below.</note>


$document = new DOMDocument();
$test = $document->createElement("test");
$foo = $document->createAttribute("foo");
header('Content-Type: application/xml');
print $document->saveXML();
print "<!-- " . $foo->value . " -->";

So, I at least see the reason why it's in the spec. Just think the
spec should clear on what to do if appending text nodes and entity
reference nodes to Attr nodes is not supported. Not having to create a
textNode and just providing .value and .nodeValue seems fine.

But, if there's no doubt that a text node should be created and
revealed with Attr.firstChild and Attr.childNodes[0] in all cases,
then I guess it's just a bug in Opera. (Looking for more comments
still though just to be sure.)


Received on Saturday, 12 January 2008 02:54:15 UTC

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