note 89616 added to function.simplexml-element-addChild
| From: | jonasmartinez at gmail dot com | Date: | Tue, 17 Mar 2009 02:56:19 +0000 |
| Subject: | note 89616 added to function.simplexml-element-addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152014@lists.php.net to get a copy of this message | ||
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/89616
Del: integrated -- https://master.php.net/note/delete/89616/integrated
Del: useless -- https://master.php.net/note/delete/89616/useless
Del: bad code -- https://master.php.net/note/delete/89616/bad+code
Del: spam -- https://master.php.net/note/delete/89616/spam
Del: non-english -- https://master.php.net/note/delete/89616/non-english
Del: in docs -- https://master.php.net/note/delete/89616/in+docs
Del: other reasons-- https://master.php.net/note/delete/89616
Reject -- https://master.php.net/note/reject/89616
Search -- https://master.php.net/manage/user-notes.php