note 89616 modified in simplexmlelement.addchild by danbrown
| From: | danbrown@php.net | Date: | Fri, 25 Sep 2009 17:16:16 +0000 |
| Subject: | note 89616 modified in simplexmlelement.addchild by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161071@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();
?>
--was--
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();
?>
http://php.net/manual/en/simplexmlelement.addchild.php