note 98993 modified in simplexmlelement.addChild by danbrown

From: Date: Wed, 21 Jul 2010 13:45:35 +0000
Subject: note 98993 modified in simplexmlelement.addChild by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171015@lists.php.net to get a copy of this message
If You want to add another XML-Element as shown former by "Lutz Elsner", but also want to consider the NameSpace, extend the given function as shown: <?php public function AddXMLElement(SimpleXMLElement $dest, SimpleXMLElement $source, $ns = NULL) { $new_dest = $dest->addChild($source->getName(), $source[0], $ns); foreach ($source->attributes($ns) as $name => $value) { $new_dest->addAttribute($name, $value, $ns); } foreach ($source->children($ns) as $child) { AddXMLElement($new_dest, $child, $ns); } } ?> --was-- If You want to add another XML-Element as shown former by "Lutz Elsner", but also want to consider the NameSpace, extend the given function as shown: public function AddXMLElement(SimpleXMLElement $dest, SimpleXMLElement $source, $ns = NULL) { $new_dest = $dest->addChild($source->getName(), $source[0], $ns); foreach ($source->attributes($ns) as $name => $value) { $new_dest->addAttribute($name, $value, $ns); } foreach ($source->children($ns) as $child) { AddXMLElement($new_dest, $child, $ns); } } http://php.net/manual/en/simplexmlelement.addChild.php

« previous php.notes (#171015) next »