XPath for selecting items with exceptions (with multiple subitems)

I have the following type of XML: -

<tagCategory name="Bike" id="10"> </tagCategory> <tagCategory name="Cars" id="22"> <excludedClass>NonDriver</excludedClass> <excludedClass>BannedFromDriving</excludedClass> </tagCategory> <tagCategory name="PogoStick" id="5"> <excludedClass>NoLegs</excludedClass> </tagCategory> 

I want to run queries where I can say:

Give me all the tagCategory elements where the excluded class is not X. For example: -

  • Give me all the tagCategory elements where the excluded class is not "NoLegs" should return "Cars and Bicycle".
  • Give me all the tagCategory elements where the excluded class is not "BannedFromDriving" should return Bike and PogoStick.
  • Give me all the tagCategory elements where the excluded class is not "NonDriver" should return Bike and PogoStick.

I use current XPath and processes elements with only one Class exception, but where there are several, it does not filter the elements as I expected.

"//tagCategory[excludedClass!='" + classification + "' or not(excludedClass)]"

Does anyone have any ideas how I can change my XPath to give me what I need?

Really appreciate any ideas.

Yours faithfully,

Phil.

+4
source share
1 answer

Try using something like:

 //tagCategory[not(excludedClass='NonDriver')] 

Example:

 //tagCategory[not(excludedClass='" + classification + "')] 
0
source

All Articles