note 13337 deleted from ref.domxml by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 19:36:20 +0000 |
| Subject: | note 13337 deleted from ref.domxml by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22103@lists.php.net to get a copy of this message | ||
I've written a function that theoretically deletes a node (from the root, but you can alter
it). Unfortunately, there's only one line that doesn't work! I'm not brilliant with
PHP, so if anyone can figure this one out (basically you need to do the equivalent of a dumpmem() on
a node) - it should work well.
function remItem($path, $nID) {
// This function deletes an item from the root, assuming that the node has an "id"
attribute.
// $path is the path to the XML doc, and $nID is the item's "id".
$d = xmldocfile($path);
$root = $d->root();
$kids = $root->children();
$y = 0;
// Loop through and find each node that ISN'T to be deleted, and put them into an array.
for ($x=0;$x<count($kids);$x++) {
if ($kids[$x]->getattr("id") != $nID) {
$notDel[$y] = $kids[$x];
$y++;
}
}
// Loop through the array and dump the XML to a string.
for ($x=0;$x<count($notDel);$x++) {
// Grr, I can't dumpmem on a node object! And so I can't do this:
// $str = $str . $notDel[$x]->dumpmem();
}
//$root->set_content($str);
$f = fopen($path, "w");
fwrite($f, $d->dumpmem());
fclose($f);
return(true);
}