note 89616 deleted from simplexmlelement.addChild by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Jan 2011 14:34:26 +0000 |
| Subject: | note 89616 deleted from simplexmlelement.addChild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176459@lists.php.net to get a copy of this message | ||
Note Submitter: jonasmartinez at gmail dot com
----
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();
?>