Edit #1:
(Thanks to @michi for pointing out that unset
is sufficient to delete a node in SimpleXML)
If you want to remove <element>
, not <feed>
as I previously thought, you can do this:
function deleteNode($feed_id)
{
$parent=$this->xml->xpath('//*[feed[@id=" '.$feed_id.' "]]');
unset($parent[0][0]);
}
Online demo
(Works for PHP>=5.2.2)
Original post
You might need DOM for this:
function deleteNode($feed_id)
{
$node=$this->xml->xpath('//feed[@id=" '.$feed_id.' "]');
$node=dom_import_simplexml($node[0]);
$parent=$node->parentNode;
$parent->removeChild($node);
$this->xml=simplexml_import_dom($parent->ownerDocument);
}
Online demo
(Noted that since it's not in a class in the demo, I used a global
for the purpose of lazy emulation. Avoid global
in your actual code.)