如何选择没有特定子节点的节点?

jrh*_*ath 6 xpath

一个相当简单的问题...... XML片段:

<bean id='Juicer'>
    <property name="electric">
        <value>false</value>
    </property>
</bean>

<bean id='Oven'>
    <property name="electric">
        <value>true</value>
    </property>
    <property name="wattage">
        <value>1000</value>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一个xpath查询,它将选择所有bean没有的查询<property name="wattage">.

我无法弄清楚如何在xpath中说"豆子没有这个孩子".

请注意,每次"瓦数"不存在时,我都不能依赖"电"属性.(另外,这个例子有点人为).

谢谢 :)

jrh*_*ath 6

好的,经过一番挖掘,我发现它:

//bean[not (property[@name='wattage'])]
Run Code Online (Sandbox Code Playgroud)

确实很简单:P