Niteliğine göre XML düğümü sil

0 Cevap php

from this xml file i want to delete picture node according to attribute id. i have written php code but it does not work.

<gallery>
      <organizate>
        <organization w="3" h="1" space="17"/>
        <organization w="4" h="2" space="17"/>
        <organization w="6" h="3" space="7"/>
      </organizate>
      <pictures>
        <picture target="events/preview/10picture1.jpg" title="test1" movie="" text="test1" link="events_calender.php" id="38"/>
        <picture target="events/preview/8picture7.jpg" title="test2" movie="" text="cxvxc" link="events_calender.php" id="39"/>
        <picture target="events/preview/5picture10.jpg" title="test3" movie="" text="test3" link="events_calender.php" id="40"/>
      </pictures>
    </gallery>

PHP code

$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->preserveWhiteSpace = FALSE;
$xPath = new DOMXPath($doc);
$doc->load('../Event_gallery.xml');
$query = sprintf('//pictures[./picture[@id="%s"]]', 38);
foreach ($xPath->query($query) as $node) {
    $node->parentNode->removeChild($node);
}
$doc->save('../Event_gallery.xml');

Ben xpath düzgün çalışmıyor düşünüyorum. kontrol foreachta gitmiyor

0 Cevap