note 89617 added to function.simplexml-element-addChild
| From: | jonasmartinez at gmail dot com | Date: | Tue, 17 Mar 2009 02:57:37 +0000 |
| Subject: | note 89617 added to function.simplexml-element-addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152015@lists.php.net to get a copy of this message | ||
I have made some adjustments in the solution of Dotnet to be more easy, thanks!
The class:
<?php
class SimpleXMLExtend extends SimpleXMLElement
{
public function addCData($nodename,$cdata_text)
{
$node = $this->addChild($nodename); //Added a nodename to create inside the function
$node = dom_import_simplexml($node);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
?>
And to use:
<?php
$xml = new SimpleXMLExtended('<?xml version = "1.0" encoding =
"UTF-8"?><root></root>');
$xml->addCData("newnode","contenthere with & $ % etc");
echo $xml->asXml();
?>
----
Server IP: 200.185.109.13
Probable Submitter: 189.32.199.89
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php
Edit -- https://master.php.net/note/edit/89617
Del: integrated -- https://master.php.net/note/delete/89617/integrated
Del: useless -- https://master.php.net/note/delete/89617/useless
Del: bad code -- https://master.php.net/note/delete/89617/bad+code
Del: spam -- https://master.php.net/note/delete/89617/spam
Del: non-english -- https://master.php.net/note/delete/89617/non-english
Del: in docs -- https://master.php.net/note/delete/89617/in+docs
Del: other reasons-- https://master.php.net/note/delete/89617
Reject -- https://master.php.net/note/reject/89617
Search -- https://master.php.net/manage/user-notes.php