#21213 [Opn->Sus]: invalid entities handling into set_attribute() and set_content()

From: Date: Wed, 01 Jan 2003 20:59:57 +0000
Subject: #21213 [Opn->Sus]: invalid entities handling into set_attribute() and set_content()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-28887@lists.php.net to get a copy of this message
ID: 21213 Updated by: chregu@php.net Reported By: flying@dom.natm.ru -Status: Open +Status: Suspended Bug Type: DOM XML related Operating System: All PHP Version: 4.3.0RC4 New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2002-12-27 10:05:50] flying@dom.natm.ru 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&amp;b'); $value = $root->set_content('a&amp;b'); echo $xml->dump_mem(); ?> It produces following results: <?xml version="1.0"?> <root a="a&amp;amp;b">a&amp;b</root> As you may see - &amp; 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

« previous php.bugs (#28887) next »