Using Xpath, how can I locate a parent element where none of multiple child elements contains a specific attribute value among a list of attribute values?
Here's a sample of my xml:
<app>
<rdg wit="#R #W #I #S #C #O #D">existunt,</rdg>
<rdg wit="#J">existant,</rdg>
</app>
My XML has hundreds of these elements that should all have the same set of eight attribute values (#R, etc.) distributed variously among two or more elements. But a few of the are missing an attribute value on the list, and I need to locate those nodes.
So I'm trying to find, say, all the <app> elements where none of the child <rdg> elements contains #R.
I can get the ones that do contain #R with //app/rdg[contains(@wit,"#R")] and I know there's a not() function, but I haven't figured out how to get these to work together.
You can accomplish this as follows:
//app[not(rdg/@wit[contains(., '#R')])]
Alternatively:
//app[not(rdg[contains(@wit, '#R')])]
This slightly convoluted approach is necessary because the apps contain multiple rdgs, so we're basically doing (to take the second example):
apps where...rdg child where...wit attribute contains #RIf 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