刪除多個空的節點我想用SimpleXML
用SimpleXML
這裏是我的代碼刪除我的XML文檔中的所有空節點:
$xs = file_get_contents('liens.xml')or die("Fichier XML non chargé");
$doc_xml = new SimpleXMLElement($xs);
foreach($doc_xml->xpath('//*[not(text())]') as $torm)
unset($torm);
$doc_xml->asXML("liens.xml");
我有print_r()
看到XPath是抓住一些東西,但是沒有任何內容從我的XML文件中刪除。
我不相信你實際上未設置()在$ doc_xml中的元素上。讓我查看SimpleXML以查看如何正確刪除節點。 – beta0x64 2011-04-05 23:03:51
[PHP SimpleXML - 刪除xpath節點]的可能重複(http://stackoverflow.com/questions/2442314/php-simplexml-remove-xpath-node) – 2011-04-06 18:02:11