ID: 21213
User updated by: [EMAIL PROTECTED]
-Summary: invalid entities handling into set_attribute() and
set_content()
Reported By: [EMAIL PROTECTED]
Status: Suspended
Bug Type: DOM XML related
Operating System: All
PHP Version: 4.3.0RC4
New Comment:
Yes, i agree with you in this point, but it also means, that you should
provide a way to parse given text value and build NodeList of Text and
EntityReference nodes. libxml2 already have such function.
Previous Comments:
------------------------------------------------------------------------
[2003-01-01 14:59:56] [EMAIL PROTECTED]
Hi
I will most certainly not add this options, since i prefer to stick to
the w3c standard at
http://www.zvon.org/xxl/DOM2reference/Output/interfaces/Element.html#setAttribute
And in my interpretation of this, php's domxml behaves correctly. The
only thing missing is setAttributeNode, which I maybe will implement,
if I find some time.
If there is setAttributeNode, then you can use the way the w3c
suggests.
chregu
------------------------------------------------------------------------
[2002-12-27 10:05:50] [EMAIL PROTECTED]
Please take a look at following example:
<?php
$xml = domxml_open_mem('<'.'?xml version="1.0"?'.'><root/>');
$root = $xml->root();
$value = $root->set_attribute('a','a&b');
$value = $root->set_content('a&b');
echo $xml->dump_mem();
?>
It produces following results:
<?xml version="1.0"?>
<root a="a&amp;b">a&b</root>
As you may see - & entity is treated as literals when it is being
set as attribute value while same entity is treated as entity reference
being set as node value.
I have checked PHP's DOMXML extension source, libxml2 sources and
discuss about this behaviour with Daniel Viellard (libxml2 maintainer)
and with some other people on public XML-related forums and here is
some information about this issue:
1. Such behaviour is not a libxml2 bug, it is expected behaviour.
Moreover it is more correct from a point of specifications.
2. There should be a way to access Attr DOM object as specified into
DOM Level 1 specification
3. There should be a way to control entites handling into passed
values.
As a way to go i want to propose you to add one additional argument to
set_attribute(), set_content() and maybe some other functions -
$options.
For now there will be 2 options:
XML_KEEP_ENTITIES - to treat all entities as entites and create them as
EntityReference DOM objects
XML_QUOTE_ENTITIES - to treat all entities as literals and hence quote
all special symbols in them (such as '&' char).
For compatibility reasons $options for set_attribute() may be set to
XML_QUOTE_ENTITIES as default value and $options for set_content() -
for XML_KEEP_ENTITIES.
Internally you probably should change xmlSetProp() call into
domxml_elem_set_attribute() to xmlNodeSetContentLen() when there is
$options=XML_KEEP_ENTITIES.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21213&edit=1