1
我的XML結構是這樣的:幫助,選擇節點使用XPath
<entity id="1000070">
<name>apple</name>
<type>category</type>
<entities>
<entity id="7002870">
<name>mac</name>
<type>category</type>
<entities>
<entity id="7002907">
<name>leopard</name>
<type>sub-category</type>
<entities>
<entity id="7024080">
<name>safari</name>
<type>subject</type>
</entity>
<entity id="7024701">
<name>finder</name>
<type>subject</type>
</entity>
</entities>
</entity>
</entities>
</entity>
<entity id="7024080">
<name>iphone</name>
<type>category</type>
<entities>
<entity id="7024080">
<name>3g</name>
<type>sub-category</type>
</entity>
<entity id="7024701">
<name>3gs</name>
<type>sub-category</type>
</entity>
</entities>
</entity>
<entity id="7024080">
<name>ipad</name>
<type>category</type>
</entity>
</entities>
</entity>
目前,我有選擇的與不分類型節點的所有實體。
$ xmlDocument-> removeNodes(「//實體[未(類型=‘類’)」)
我不知道我會選擇不包含類型=類別或類型的所有節點=子類別。
我曾嘗試用:
$xmlDocument->removeNodes("//entity[not(type='category')] | //entity[not(type='sub-category')]")
但它不工作!