From: [EMAIL PROTECTED] Operating system: All PHP version: 4.3.0RC4 PHP Bug Type: DOM XML related Bug description: invalid entities handling into set_attribute() and set_content()
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 bug report at http://bugs.php.net/?id=21213&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=21213&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=21213&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=21213&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=21213&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=21213&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=21213&r=support Expected behavior: http://bugs.php.net/fix.php?id=21213&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=21213&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=21213&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=21213&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21213&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=21213&r=dst IIS Stability: http://bugs.php.net/fix.php?id=21213&r=isapi