开发者

How to select nodes that has X as descendant using xpath

consider following example:

<root>
   <instruments>
      <flute>
         <baz>bazik</baz>
      </flute>
      <guitar>
         <deep>
            <baz>mor开发者_运维技巧e 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?


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

so the expression can be

/root/instruments/*[descendant::baz]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜