note 95931 deleted from simplexmlelement.addChild by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Jan 2011 14:34:16 +0000 |
| Subject: | note 95931 deleted from simplexmlelement.addChild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176454@lists.php.net to get a copy of this message | ||
Note Submitter: martin (at) richtwerk
----
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.