note 54486 added to ref.simplexml

From: Date: Wed, 06 Jul 2005 02:44:24 +0000
Subject: note 54486 added to ref.simplexml
Groups: php.notes 
Request: Send a blank email to php-notes+get-91496@lists.php.net to get a copy of this message
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); } } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.simplexml.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54486 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54486&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54486&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91496) next »