我想使用删除 XML 文档中的所有空节点SimpleXML
这是我的代码:
$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 文件中删除任何内容。
$file = 'liens.xml';
$xpath = '//*[not(text())]';
if (!$xml = simplexml_load_file($file)) {
throw new Exception("Fichier XML non chargé");
}
foreach ($xml->xpath($xpath) as $remove) {
unset($remove[0]);
}
$xml->asXML($file);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)