note 68618 added to function.simplexml-element-addchild
| From: | fred at misterbob dot nl | Date: | Thu, 03 Aug 2006 16:23:35 +0000 |
| Subject: | note 68618 added to function.simplexml-element-addchild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115520@lists.php.net to get a copy of this message | ||
<?php
class XMLElement extends SimpleXMLElement {
public function addElement (XMLElement $xmlTree,$root=false) {
if ($root) {
$child = $this->addChild ($xmlTree->getName());
foreach ($xmlTree->attributes() as $k => $v) {
$child->addAttribute($k,$v);
}
$child->addElement($xmlTree);
} else {
foreach ($xmlTree as $childName => $childTree) {
$child = $this->addChild($childName,(string) $childTree); // this is not comletely correct
foreach ($childTree->attributes() as $k => $v) {
$child->addAttribute($k,$v);
}
$child->addElement($childTree->children());
}
}
}
}
$xmlMovies = "<movies><movie name=\"Shawshank
Redemption\"><plot>The life of Andy Dufresne changes when he is convicted and jailed
for the murder of his wife.</plot></movie></movies>";
$elMovies = new XMLElement($xmlMovies);
$xmlGodfather = "<movie name=\"Godfather\"><plot>The aging patriarch of
an organized crime dynasty transfers control of his clandestine empire to his reluctant
son.</plot></movie>";
$elGodfather = new XMLElement ($xmlGodfather);
$elMovies->addElement($elGodfather,true);
echo $elMovies->asXML();
?>
Method to append (Simple)XMLElements to each other.
----
Server IP: 194.109.193.119
Probable Submitter: 62.108.8.165
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addchild.php
Edit -- https://master.php.net/note/edit/68618
Del: integrated -- https://master.php.net/note/delete/68618/integrated
Del: useless -- https://master.php.net/note/delete/68618/useless
Del: bad code -- https://master.php.net/note/delete/68618/bad+code
Del: spam -- https://master.php.net/note/delete/68618/spam
Del: non-english -- https://master.php.net/note/delete/68618/non-english
Del: in docs -- https://master.php.net/note/delete/68618/in+docs
Del: other reasons-- https://master.php.net/note/delete/68618
Reject -- https://master.php.net/note/reject/68618
Search -- https://master.php.net/manage/user-notes.php