note 86085 added to function.simplexml-element-addChild
| From: | Donet at osu1 dot php dot net | Date: | Thu, 02 Oct 2008 14:11:43 +0000 |
| Subject: | note 86085 added to function.simplexml-element-addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144976@lists.php.net to get a copy of this message | ||
I found this easy way to create a CDATA section as child value:
I extend the class SimpleXMLElement:
class SimpleXMLExtended extends SimpleXMLElement
{
public function addCData($cdata_text)
{
$node= dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
Then in the main code:
$xml = new SimpleXMLExtended('<?xml version = "1.0" encoding =
"UTF-8"?><root></root>');
$mynode = $xml->addChild("myname");
$mynode->addCData("my name contains everything I want &%<>");
echo $xml->asXml();
----
Server IP: 69.147.83.197
Probable Submitter: 89.96.52.107
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php
Edit -- https://master.php.net/note/edit/86085
Del: integrated -- https://master.php.net/note/delete/86085/integrated
Del: useless -- https://master.php.net/note/delete/86085/useless
Del: bad code -- https://master.php.net/note/delete/86085/bad+code
Del: spam -- https://master.php.net/note/delete/86085/spam
Del: non-english -- https://master.php.net/note/delete/86085/non-english
Del: in docs -- https://master.php.net/note/delete/86085/in+docs
Del: other reasons-- https://master.php.net/note/delete/86085
Reject -- https://master.php.net/note/reject/86085
Search -- https://master.php.net/manage/user-notes.php