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.

example.xml:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css"
href="data:text/css;charset=utf-8,example%2Ctest%2Cnote%7Bdisplay%3Ablock%3Bmargin%3A5px%7D"?>
<!DOCTYPE example [<!ENTITY magic "zam">]>
<example>
    <note>You should see zip&magic;bam below.</note>
</example>

example.php:

<?php
$document = new DOMDocument();
$document->load('example.xml');
$test = $document->createElement("test");
$test->appendChild($document->createTextNode("zip"));
$test->appendChild($document->createEntityReference("magic"));
$test->appendChild($document->createTextNode("bam"));
$foo = $document->createAttribute("foo");
$foo->appendChild($document->createTextNode("zip"));
$foo->appendChild($document->createEntityReference("magic"));
$foo->appendChild($document->createTextNode("bam"));
$test->setAttributeNode($foo);
$document->documentElement->appendChild($test);
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.)

Thanks

-- 
Michael
Received on Saturday, 12 January 2008 02:54:15 GMT

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