note 89617 deleted from function.simplexml-element-addChild by danbrown

From: Date: Tue, 17 Mar 2009 02:59:19 +0000
Subject: note 89617 deleted from function.simplexml-element-addChild by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152017@lists.php.net to get a copy of this message
Note Submitter: jonasmartinez at gmail dot com ---- 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(); ?>

« previous php.notes (#152017) next »