note 84118 added to function.simplexml-element-addChild
| From: | kobrasrealm at gmail dot com | Date: | Sat, 28 Jun 2008 21:22:54 +0000 |
| Subject: | note 84118 added to function.simplexml-element-addChild | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140901@lists.php.net to get a copy of this message | ||
Here's a handy workaround to accommodate the lack of a $xml->deleteChild() function.
It's not perfect, but it's a start (and it works for what I'm using it for):
<?php
// Workaround by Kobra. http://www.kobrasrealm.net
function simplexml_deleteChild($parent, $childname, $parentname)
{
$temp = simplexml_load_string(str_replace("#","?","<#xml
version=\"1.0\"#>\n<".$parentname.">\n</".$parentname.">"));
foreach($parent as $t)
{
if($t->getName() != $childname)
{
$name = $t->getName();
$value = eval("return \$parent->".$name.";");
$temp->addChild($t->getName(), $value);
}
}
return $temp;
}
?>
I have not tested this with multi-level XML files; but like I said, it's a start.
----
Server IP: 69.147.83.197
Probable Submitter: 71.3.86.105
----
Manual Page -- http://www.php.net/manual/en/function.simplexml-element-addChild.php
Edit -- https://master.php.net/note/edit/84118
Del: integrated -- https://master.php.net/note/delete/84118/integrated
Del: useless -- https://master.php.net/note/delete/84118/useless
Del: bad code -- https://master.php.net/note/delete/84118/bad+code
Del: spam -- https://master.php.net/note/delete/84118/spam
Del: non-english -- https://master.php.net/note/delete/84118/non-english
Del: in docs -- https://master.php.net/note/delete/84118/in+docs
Del: other reasons-- https://master.php.net/note/delete/84118
Reject -- https://master.php.net/note/reject/84118
Search -- https://master.php.net/manage/user-notes.php