gpeire Posted December 2, 2007 Share Posted December 2, 2007 I like to remove a particular <image/> in an XML file with the following structure: <gallery> <albums> <album title="blabla1"> <image thumbnail="1.jpg" big="1.jpg></image> <image thumbnail="2.jpg" big="2.jpg></image> </album> <album title="blabla2> <image thumbnail="a.jpg" big="a.jpg></image> <image thumbnail="b.jpg" big="b.jpg></image> </album> </albums> </gallery> I use this code (ex. $pict_name == "1.jpg"): $doc = new DOMDocument(); $doc->load($file); $root = $doc->documentElement; $albums = $root->getElementsByTagName("album"); foreach($albums as $album){ $images = $album->getElementsByTagName("image"); foreach ($images as $img) { if(htmlentities($img->getAttribute('thumbnail')) == $pict_name){ $okay = $album->removeChild($img); } } } $doc->saveXML(); When I echo $album and $img it gives me the right string but removeChild does'nt work. I'm new to using DOM with PHP, can anyone help me pls? ??? Link to comment https://forums.phpfreaks.com/topic/79810-dom-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.