Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select nodes that DO NOT have a particular child node?

Tags:

xpath

A rather simple problem... XML Fragment:

<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>

I'm trying to write an xpath query that will select all beans that do not have a <property name="wattage">.

I cant figure out how to say "beans not having this child" in xpath.

Note that I cannot rely on the "electric" property to be false each time the "wattage" is absent. (also, this example is kinda contrived).

Thanks :)

like image 306
jrharshath Avatar asked Oct 11 '10 12:10

jrharshath


2 Answers

Okay, after a little digging i figured it out:

//bean[not (property[@name='wattage'])]

Simple indeed :P

like image 111
jrharshath Avatar answered Sep 22 '22 21:09

jrharshath


Try

//bean[not(property[@name='wattage'])]
like image 25
GôTô Avatar answered Sep 23 '22 21:09

GôTô