I have an XML:
<root>
<level name="main">
<level name="sub_1">
<content id="abc123" />
</level>
</level>
</root>
I would like to search for the node with id that is abc123 and delete the <content> and its parent <level>
So the end result would be:
<root>
<level name="main">
</level>
</root>
I have tried this in PHP without result, what am I doing wrong?
$doc = new DOMDocument;
$doc->loadxml($xml_from_file);
$xpath = new DOMXPath($doc);
$node_list = $xpath->query("content[@id='abc123']/parent::*");
$node = $node_list->item(0);
$doc->removeChild($node);
DOMDocument::loadXMLtakes XML. UseDOMDocument::loadfor filename.loadXML