<Root>
<SomeElement>
...
<Wanted>.....</Wanted>
<UnWanted>
<Wanted>.....</Wanted>
</UnWanted>
<Wanted>.....</Wanted>
...
</SomeElement>
</Root>
I want to select the "Wanted
" Elements which are inside "SomeElement
" at ANY level but not childs of "UnWanted
" Element.
With the XPath /Root/SomeElement//Wanted
I'm not able to exclude the childs of UnWanted
.
You could try
/Root/SomeElement//Wanted[not(ancestor::UnWanted)]
This would exclude all Wanted
elements that are a child, grandchild, etc. (at any level) of an UnWanted
element. If you only want to exclude Wanted
elements that are a direct child of UnWanted
(but still include those that are grandchildren, etc.) then change ancestor::
to parent::
/Root/SomeElement//Wanted[not(parent::UnWanted)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With