Can't delete xml child



I have an xml file with the following structure below:



<szallito>
<vasarlo>
<id>217</id>
<posta>300</posta>
</vasarlo>
</szallito>


I have the function below to delete the specific child of the xml file:



function deleteChild($session_file,$child){
$doc = new DOMDocument;
$doc->load($session_file);
$xml_struct = $doc->documentElement;
$to_delete = $xml_struct->getElementsByTagName($child)->item(0);
print_r($to_delete);
$delete = $xml_struct->removeChild($to_delete);
$doc->save($session_file);
}


However it doesn't seem to work for me, although I wrote it according to the php.net documentation and I've tried the answers from another topics without success.


The log says that it can't find the child to delete, which is in variable $to_delete, but that variable is the right DOMElement Object (according to the print_r).


Could you help me out with this one? What am I missing?


No comments:

Post a Comment