Php 根据属性从XML中删除节点
从这个xml文件中,我想根据属性id删除图片节点。 我已经编写了php代码,但它不起作用Php 根据属性从XML中删除节点,php,xml,Php,Xml,从这个xml文件中,我想根据属性id删除图片节点。 我已经编写了php代码,但它不起作用 <gallery> <organizate> <organization w="3" h="1" space="17"/> <organization w="4" h="2" space="17"/> <organization w="6" h="3" space="7"/>
<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>
我认为xpath工作不正常。控件没有进入foreach问题是在将文档传递给DOMXPath后正在加载该文档 改变
$xPath = new DOMXPath($doc);
$doc->load('../Event_gallery.xml');
到
那么它应该会起作用
要仅删除具有给定id的picture元素而不是整个父元素,请将XPath更改为
//pictures/picture[@id="38"]
还有一件事我只想删除节点图片而不是图片。这次它会删除图片。你能帮忙吗?
$doc->load('../Event_gallery.xml');
$xPath = new DOMXPath($doc);
//pictures/picture[@id="38"]