|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-03-18 12:13 UTC] rrichards@php.net
[2012-08-23 20:15 UTC] phpbug at mailinator dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 10:00:01 2025 UTC |
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>