Search code examples
xpath

Xpath where we can do value check for multiple values .//Time[@TOD='Day']//Task[@Status='COMPLETED']


I have the below xpath that works on my XML easily when only one status needs to be checked:

.//Time[@TOD='Day']//Task[@Status='COMPLETED']

What is the way that I would be able to do something like so:

.//Time[@TOD='Day']//Task[@Status in 'COMPLETED', 'BLOCKED']
etc

Basically status attrib to have a in check rather than an equal to


Solution

  • In XPath 2 or later, if your XPath processor/API supports it, you can use e.g. .//Time[@TOD='Day']//Task[@Status = ('COMPLETED', 'BLOCKED')]. In XPath 1.0 use or e.g. .//Time[@TOD='Day']//Task[@Status = 'COMPLETED' or @Status = 'BLOCKED'].