note 99071 added to class.simplexmlelement

From: Date: Mon, 26 Jul 2010 11:47:35 +0000
Subject: note 99071 added to class.simplexmlelement
Groups: php.notes 
Request: Send a blank email to php-notes+get-171124@lists.php.net to get a copy of this message
I'm using SimpleXML for, ofcourse, it's simplicity, however I did wanted to manipulate the xml and combining one SimpleXMLElement with any other, so I wrote this function to add a SimpleXMLElement-child. <?php function SimpleXMLElement_append($key, $value) { // check class if ((get_class($key) == 'SimpleXMLElement') && (get_class($value) == 'SimpleXMLElement')) { // check if the value is string value / data if (trim((string) $value) == '') { // add element and attributes $element = $key->addChild($value->getName()); foreach ($value->attributes() as $attKey => $attValue) { $element->addAttribute($attKey, $attValue); } // add children foreach ($value->children() as $child) { SimpleXMLElement_append($element, $child); } } else { // set the value of this item $element = $key->addChild($value->getName(), trim((string) $value)); } } else { // throw an error throw new Exception('Wrong type of input parameters, expected SimpleXMLElement'); } } ?> I'd recommend SimpleXMLElement to extend it's addChild() function with the functionalitity above. ---- Server IP: 91.199.167.223 Probable Submitter: 212.61.145.66 ---- Manual Page -- http://www.php.net/manual/en/class.simplexmlelement.php Edit -- https://master.php.net/note/edit/99071 Del: integrated -- https://master.php.net/note/delete/99071/integrated Del: useless -- https://master.php.net/note/delete/99071/useless Del: bad code -- https://master.php.net/note/delete/99071/bad+code Del: spam -- https://master.php.net/note/delete/99071/spam Del: non-english -- https://master.php.net/note/delete/99071/non-english Del: in docs -- https://master.php.net/note/delete/99071/in+docs Del: other reasons-- https://master.php.net/note/delete/99071 Reject -- https://master.php.net/note/reject/99071 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171124) next »