note 95931 added to simplexmlelement.addChild
| From: | (at) | Date: | Fri, 29 Jan 2010 09:01:24 +0000 |
| Subject: | note 95931 added to simplexmlelement.addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165481@lists.php.net to get a copy of this message | ||
another comment on special chars:
it is not, that addChild doesn't escape special chars and addAttribute does
(as Andy suggested)
nor that addChild does automatically escape all XML characters as necessary
(as Dmitr suggested).
addChild does some sort of html_entity_decode and stores the decoded result in the SimpleXMLElement.
So it assumes the $value to be properly encoded xml data, not just any text.
This is, why addChild vomits:
Warning: SimpleXMLElement::addChild(): unterminated entity reference stuff
when executing
<?php
$msg = "This is a test & stuff.";
$xml = new SimpleXMLElement($test);
$xml->addAttribute('foo', $msg);
?>
(tries to decode unknown entity &stuff (semicolon missing))
Encoding of special characters is done by asXML.
This is, why Andy's hack does work.
----
Server IP: 217.160.72.57
Probable Submitter: 62.245.157.124
----
Manual Page -- http://www.php.net/manual/en/simplexmlelement.addChild.php
Edit -- https://master.php.net/note/edit/95931
Del: integrated -- https://master.php.net/note/delete/95931/integrated
Del: useless -- https://master.php.net/note/delete/95931/useless
Del: bad code -- https://master.php.net/note/delete/95931/bad+code
Del: spam -- https://master.php.net/note/delete/95931/spam
Del: non-english -- https://master.php.net/note/delete/95931/non-english
Del: in docs -- https://master.php.net/note/delete/95931/in+docs
Del: other reasons-- https://master.php.net/note/delete/95931
Reject -- https://master.php.net/note/reject/95931
Search -- https://master.php.net/manage/user-notes.php