Jump to content

DOM question


gpeire

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.