#44458 [Opn->Bgs]: Ampersand sign in SimpleXMLElement->addChild() causes incomplete XML
| From: | rrichards@php.net | Date: | Tue, 18 Mar 2008 12:13:22 +0000 |
| Subject: | #44458 [Opn->Bgs]: Ampersand sign in SimpleXMLElement->addChild() causes incomplete XML | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-123416@lists.php.net to get a copy of this message | ||
ID: 44458
Updated by: rrichards@php.net
Reported By: sergej at halogen-dg dot com
-Status: Open
+Status: Bogus
Bug Type: SimpleXML related
Operating System: FreeBSD, Linux
PHP Version: 5.2.5
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
& must be escaped
Previous Comments:
------------------------------------------------------------------------
[2008-03-17 19:29:53] sergej at halogen-dg dot com
Description:
------------
SimpleXMLElement->addChild() causes warning message and produces
incomplete XML in case when the second argument contains ampersand
sign '&'. Text after ampersand is absent in output XML.
In the same time escaping of other XML special symbols in tag body
works OK. Also all XML special symbols in tag attributes are escaped
OK.
Reproduce code:
---------------
<?
$sxml=new SimpleXMLElement('<?xml version="1.0"
encoding="utf-8"?><test></test>');
// Quotes
$sitem=$sxml->addChild('tag',"'");
$sitem->addAttribute('attr',"'");
$sitem=$sxml->addChild('tag','"');
$sitem->addAttribute('attr','"');
// Brackets
$sitem=$sxml->addChild('tag','<');
$sitem->addAttribute('attr','<');
$sitem=$sxml->addChild('tag','>');
$sitem->addAttribute('attr','>');
// Ampersand
$sitem=$sxml->addChild('tag','Smith & Wesson');
$sitem->addAttribute('attr','Smith & Wesson');
// Result XML
print($sxml->asXML());
?>
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<test><tag attr="'">'</tag><tag
attr=""">"</tag><tag
attr="<"><</tag><tag
attr=">">></tag><tag attr="Smith
& Wesson">Smith & Wesson</tag></test>
Actual result:
--------------
PHP Warning: SimpleXMLElement::addChild(): unterminated entity
reference Wesson in xml.php on line 14
Warning: SimpleXMLElement::addChild(): unterminated entity reference
Wesson in xml.php on line 14
<?xml version="1.0" encoding="utf-8"?>
<test><tag attr="'">'</tag><tag
attr=""">"</tag><tag
attr="<"><</tag><tag
attr=">">></tag><tag attr="Smith
& Wesson">Smith </tag></test>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44458&edit=1