I have an XML document:
I want to find the <data> with attribute 'fruit' that is an "orange", and delete the whole <data> so that the resulting XML looks like
How do I do this with PHP? I'm going nuts...
Here's what I currently have, but it's not working:
Any ideas? Thanks.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<level1>
<data fruit="apple"/>
<data fruit="orange"/>
<data fruit="pear"/>
</level1>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<level1>
<data fruit="apple"/>
<data fruit="pear"/>
</level1>
Here's what I currently have, but it's not working:
Code:
$doc = simplexml_load_file("file.xml");
foreach($doc->data as $data) {
if($data['fruit'] == 'orange') {
$dom=dom_import_simplexml($data);
$dom->parentNode->removeChild($dom);
}
}