tags:

views:

70

answers:

1

consider following example:

<root>
   <instruments>
      <flute>
         <baz>bazik</baz>
      </flute>
      <guitar>
         <deep>
            <baz>more bazik</baz>
         </deep>
      </guitar>
      <drum>
         <foo>fooled</foo>
      </drum>
   </instruments>
</root>

I want to select flute and guitar because they both contain baz as a descendant node. How can I do that?

+7  A: 

the key is to use predicate [descendant::baz]

so the expression can be

/root/instruments/*[descendant::baz]
vtd-xml-author
Or, for short: `/root/instruments/*[.//baz]`
Tomalak