我的XML文件被命名爲cgal.xml根據從XML刪除的屬性
<?xml version="1.0"?>
<item>
<name><![CDATA[<img src="event_pic/pic1.jpg" />CALENDAR]]></name>
<description title="NAM ELIT AGNA, ENDRERIT SIT AMET, TINCIDUNT AC." day="13" month="8" year="2010" id="15"><![CDATA[<img src="events/preview/13p1.jpg" /><font size="8" color="#6c6e74">In Gladiator, victorious general Maximus Decimus Meridias has been named keeper of Rome and its empire by dying emperor Marcus Aurelius, so that rule might pass from the Caesars back to the people and Senate. Marcus\' neglected and power-hungry son, Commodus, has other ideas, however. Escaping an ordered execution, Maximus hurries back to his home in Spain, too l</font>]]></description>
</item>
和我的PHP函數是: -
$doc = new DOMDocument;
$doc->formatOutput = TRUE;
$doc->preserveWhiteSpace = FALSE;
$doc->simplexml_load_file('../cgal.xml');
foreach($doc->description as $des)
{
if($des['id'] == $id) {
$dom=dom_import_simplexml($des);
$dom->parentNode->removeChild($dom);
}
}
$doc->save('../cgal.xml');
ID動態傳遞
我想刪除節點根據ID
你的問題是什麼?此外,也許這些問題之一可以幫助:http://stackoverflow.com/search?q=php+remove+node – 2010-08-06 12:10:55