1
我有一個xml其格式是這樣的:PHP DOM使用XPath去除標籤
<root>
<a>1</a>
<b>2</b>
<c></c>
</root>
這是我曾嘗試代碼:
$to = 3;
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$dom->load("../xxx.xml");
$xpath = new DOMXPath($dom);
$query = "/root/*[position()=$to]";
$nodes = $xpath->query($query);
$node = $nodes[0];
$dom->removeChild($node);
$dom->save("../xxx.xml", LIBXML_NOEMPTYTAG);
如何刪除標籤與名字「c」?