note 54486 deleted from ref.simplexml by derick

From: Date: Thu, 13 Oct 2005 13:43:35 +0000
Subject: note 54486 deleted from ref.simplexml by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96948@lists.php.net to get a copy of this message
Note Submitter: brcavanaghATNOSPAM.hotmail.com ---- I posted above regarding about some of the shortcomings of using simpleXML a while back, because it meant in many cases if you wanted to use it for more, you had to use cumbersome DOM methods to get the features you needed. Well I decided to write a class in PHP 5 to deal with the more annoying problems with it. It is called extendedSimpleXML and it really helps out it you want to use SimpleXML for more than just reading documents, since you can add/remove/replace. Just use it like $xml = new extendedSimpleXML($xml_string); <?PHP class extendedSimpleXML extends simpleXMLElement{ public function cloneNode(){ return new extendedSimpleXML($this->asXML()); } public function appendChild($node){ $parent = dom_import_simplexml($this); $node = dom_import_simplexml($node); $node = clone $node; $parent->appendChild($node); } public function removeChild($node){ $child = dom_import_simplexml($node); $parent = dom_import_simplexml($this); $parent->removeChild($node); } public function removeNode(){ $node = dom_import_simplexml($this); $parent = $node->parentNode; $parent->removeChild($node); } public function replaceNode($newNode){ $node = dom_import_simplexml($this); $parent = $node->parentNode; $newChild = dom_import_simplexml($newNode); $parent->removeChild(clone $newChild,$node); } public function replaceChild($newNode,$oldNode){ $parent = dom_import_simplexml($this); $oldchild = dom_import_simplexml($oldNode); $newChild = dom_import_simplexml($newNode); $parent->replaceChild(clone $newChild, $oldChild); } } ?>

« previous php.notes (#96948) next »