我的xml结构如下所示:
<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-&GT; removeNodes( “//实体[不(类型= '类别')]”)
我想知道如何选择不包含type = category OR type = sub-category的所有节点。
我尝试过:
$xmlDocument->removeNodes("//entity[not(type='category')] | //entity[not(type='sub-category')]")
但它不起作用!
答案 0 :(得分:3)
答案 1 :(得分:2)
我想你想要:
//entity[not(type='category' or type='sub-category')]
这是一个很好的(如果简短的)资源:http://www.w3schools.com/xpath/xpath_operators.asp