Deleting an XML Node within a parent



I have an XML file with a root, a parent node and some inner nodes. If I use DOM->load(myxmlfile.xml) is it possible to traverse through the nodes and remove the imageurlnode?


I have tried this example:



$doc = new DOMDocument;
$doc->load('book.xml');

$book = $doc->documentElement;

// we retrieve the chapter and remove it from the book
$chapter = $book->getElementsByTagName('chapter')->item(0);
$oldchapter = $book->removeChild($chapter);

echo $doc->saveXML();


But this only removes items from underneath root. My XML has the following structure:



<root>
<property>
<imageurl></imageurl>
</property
</root>


So when it comes to removing the imgurl node (as it's inside a parent inside the root) how would I remove it?


No comments:

Post a Comment