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? ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.