如何在xpath中使用not contains()? [英] How to use not contains() in xpath?

查看:847
本文介绍了如何在xpath中使用not contains()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些XML的结构如下:

I have some XML that is structured like this:

<whatson>
  <productions>    
    <production>
      <category>Film</category>
    </production>
    <production>
      <category>Business</category>
    </production>
    <production>
      <category>Business training</category>
    </production>
  </productions>
</whatson>

我需要选择每个类别都不包含业务的产品(因此

And I need to select every production with a category that doesn't contain "Business" (so just the first production in this example).

xpath可能吗?我尝试按照这些方法工作,但无济于事:

Is this possible with xpath? I tried working along these lines but got nowhere:

//production[not(contains(category,'business'))]


推荐答案

XPath查询区分大小写。看完您的示例(顺便说一下,它真棒,似乎没人提供示例了!),我只需将 business更改为 Business即可得到想要的结果

XPath queries are case sensitive. Having looked at your example (which, by the way, is awesome, nobody seems to provide examples anymore!), I can get the result you want just by changing "business", to "Business"

//production[not(contains(category,'Business'))]

我已经通过在Chrome中打开XML文件并使用Developer工具执行XPath查询来对此进行了测试,并且它还给了我Film类。

I have tested this by opening the XML file in Chrome, and using the Developer tools to execute that XPath queries, and it gave me just the Film category back.

这篇关于如何在xpath中使用not contains()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆