Reputation: 26583
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 bean
s 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 :)
Upvotes: 6
Views: 3552
Reputation: 26583
Okay, after a little digging i figured it out:
//bean[not (property[@name='wattage'])]
Simple indeed :P
Upvotes: 6
Reputation: 243479
In case the current node is the parent element of the bean
elements, one XPath expression that selects the wanted elements is:
bean[not(property/@name = 'wattage')]
This is probably the simplest such expression (has only a single predicate).
This expression translated in English says:
Select all bean
children of the current node for which no name
attribute of any of their property
children is the string "wattage"
.
Upvotes: 2