PHP SimpleXML - Remove xpath node

Posted by Peter John on Stack Overflow See other posts from Stack Overflow or by Peter John
Published on 2010-03-14T13:37:29Z Indexed on 2010/03/14 13:45 UTC
Read the original article Hit count: 487

Filed under:
|

Hi, I'm a little confused as to how i can delete a parent node of something which i can find via an xpath search:

$xml = simplexml_load_file($filename);
$data = $xml->xpath('//items/info[item_id="' . $item_id . '"]');
$parent = $data[0]->xpath("parent::*");
unset($parent);

So, it finds the item id, no problems there - but the unset isnt getting rid of this <items> node. All i want to do is remove the <items>...</items> for this product. Obviously, there are loads of <items> nodes in the xml file so it cant do unset($xml->data->items) as that would delete everything.

Any ideas much appreciated :-)

© Stack Overflow or respective owner

Related posts about php

Related posts about simplexml