- simplexml_load_string: documentation ( source)
- dom_import_simplexml: documentation ( source)
- simplexml_import_dom: documentation ( source)
<?php
$xml=simplexml_load_string(<<<XML
<element>
<feed id=" 9 ">
<title>test</title>
<table>feeds</table>
<link/>
<feed_type>API</feed_type>
<affiliate/>
<mwst>ja</mwst>
<tld>DE</tld>
<query/>
</feed>
</element>
XML
);
function deleteNode($feed_id)
{
global $xml;
$node=$xml->xpath('//feed[@id=" '.$feed_id.' "]');
$node=dom_import_simplexml($node[0]);
$parent=$node->parentNode;
$parent->removeChild($node);
$xml=simplexml_import_dom($parent->ownerDocument);
}
echo $xml->asXML();
echo "\n";
deleteNode("9");
echo $xml->asXML();