开发者

Xpath: Select only non-nested pre tags

开发者 https://www.devze.com 2023-03-09 06:00 出处:网络
Can anyone help me with a xpath selector to select all the pre tags with开发者_JAVA技巧in a page, but only if they are not within another pre tag? (even if multiple levels deep)

Can anyone help me with a xpath selector to select all the pre tags with开发者_JAVA技巧in a page, but only if they are not within another pre tag? (even if multiple levels deep)

It would be awesome if this could all be done within one selector, rather than just selecting all pre tags and breaking if they have pre as a parent.


Like this? //pre[not(ancestor::pre)]


Or for completeness, in XPath 2.0

//pre except //pre//pre


Try:

//pre[not(ancestor::pre)]
0

精彩评论

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