DOM 'removeChild' ... what am I doing wrong?

Discussion in 'PHP' started by gpeire, Dec 1, 2007.

  1. #1
    I like to remove an 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();

    I'm new to using DOM with PHP, can anyone help me pls?
     
    gpeire, Dec 1, 2007 IP