How to use not contains() in xpath?

Jason picture Jason · Jun 14, 2012 · Viewed 167.6k times · Source

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).

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

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

Answer

Arran picture Arran · Jun 14, 2012

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'))]

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.