#40105 [Asn->Bgs]: DOMDocument->createElement() unescapes numeric character references in values
| From: | chregu@php.net | Date: | Thu, 18 Jan 2007 11:05:19 +0000 |
| Subject: | #40105 [Asn->Bgs]: DOMDocument->createElement() unescapes numeric character references in values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-107719@lists.php.net to get a copy of this message | ||
ID: 40105
Updated by: chregu@php.net
Reported By: fletch at pobox dot com
-Status: Assigned
+Status: Bogus
Bug Type: DOM XML related
Operating System: linux
PHP Version: 5.2.0
Assigned To: chregu
New Comment:
<root> </root> and <root> </root> (the space here being
a non breakable space) is the same in the XML context... It
doesn't matter, if your write a character as numerical entity
or with the actual char. It's the same. You have to live with
that.
And please don't just assign bugs...
Previous Comments:
------------------------------------------------------------------------
[2007-01-18 06:01:08] fletch at pobox dot com
I'm aware of the differences in escaping between createElement() and
createTextNode() and neither one does what I describe. createElement()
unescapes NCRs (as I described in the original description) while
createTextNode() escapes values.
In a nutshell, using createElement() I end up with "<root> </root>",
and using createTextNode() I end up with "<root>&#0160;</root>".
There is no way to generate the literal XML "<root> </root>"
using either createElement() OR createTextNode()
------------------------------------------------------------------------
[2007-01-12 07:44:43] chregu@php.net
It was decided to leave it as it is (for backwards
compatibility reasons)
use $dom->createTextNode() for the behaviour you want.
------------------------------------------------------------------------
[2007-01-11 23:28:30] fletch at pobox dot com
There's a trivial error in the expected result text: the string length
produced by var_dump() should be 65, not 59.
------------------------------------------------------------------------
[2007-01-11 23:26:27] fletch at pobox dot com
Description:
------------
DOMDocument->createElement() unescapes any numeric character references
(NCRs) contained in the value passed to its optional second parameter.
It should preserve the value as passed.
Reproduce code:
---------------
<?php
$dom = new DOMDocument( "1.0", 'UTF-8' );
$dom->appendChild( $dom->createElement( 'root', '& ' )
);
var_dump( trim( $dom->saveXML() ) );
?>
Expected result:
----------------
string(59) "<?xml version="1.0" encoding="UTF-8"?>
<root>& </root>"
Actual result:
--------------
string(59) "<?xml version="1.0" encoding="UTF-8"?>
<root>& </root>"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40105&edit=1