go to bug id or search bugs for
From manual page: http://www.php.net/simplexmlelement.addchild
addChild treats <my_string> as a tag nd removes it completely
Add a Patch
Add a Pull Request
Can you provide a test script and its actual vs. expected output to show exactly what you mean?
$xml_header = "<?xml version='1.0' encoding='utf-8'?><xml/>";
$xml = new SimpleXMLElement($xml_header);
$xml->addChild("first_string","this is <mystring>");
$xml->addChild("second_string","this is < mystring>");
echo "<pre>" . $xml->first_string . "<br />"; // 'this is '
echo $xml->second_string . "</pre>"; // 'this is < mystring>'
Shouldn't the values passed to xmlNewChild in addChild go through BAD_CAST like
all other Xml related methods do?
Something is wrong here.
The tag is not removed, it's not encoded anymore. But &entity; are removed.
> Something is wrong here.
No, everything works as expected, albeit the behavior is not
documented. Firstly, I doubt that the tag has ever been removed
as reported originally; almost certainly the tag was simply not
shown by the browser.
Anyhow, SimpleXMLElement::addChild() uses xmlNewChild() under the
hood, and the relevant documentation states:
| If @content is non NULL, a child list containing the TEXTs and
| ENTITY_REFs node will be created. NOTE: @content is supposed to be
| a piece of XML CDATA, so it allows entity references. XML special
| chars must be escaped first by using xmlEncodeEntitiesReentrant(),
| or xmlNewTextChild() should be used.
When SimpleXMLElement::__toString() is called, it uses
xmlNodeListGetString() under the hood, whose documentation
| Build the string equivalent to the text contained in the Node
| list made of TEXTs and ENTITY_REFs
So *known* entity refs are resolved, while unresolvable entity
refs are skipped (€ is not predefined).
Note that creating empty child nodes, and setting their value
afterwards via assignment has different results, because the
assignment applies xmlEncodeEntitiesReentrant() automatically.
Changing to documentation issue.