[英]How do I use Xpath to locate parent node where a child node does not contain an attribute?
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?使用 Xpath,如何在属性值列表中定位多个子元素都不包含特定属性值的父元素?
Here's a sample of my xml:这是我的 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.我的 XML 有数百个这样的元素,它们都应该具有相同的一组八个属性值(#R 等),它们以不同的方式分布在两个或多个元素中。 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.所以我试图找到所有
<app>
元素,其中没有子<rdg>
元素包含 #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.我可以得到那些包含#R与那些
//app/rdg[contains(@wit,"#R")]
我知道有没有()函数,但我还没有想出如何让这些来一起工作。
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 app
s contain multiple rdg
s, so we're basically doing (to take the second example):这种稍微复杂的方法是必要的,因为
app
包含多个rdg
,所以我们基本上是在做(以第二个例子为例):
app
s where...app
所在的位置...rdg
child where...rdg
孩子在哪里......wit
attribute contains #R
wit
属性包含#R
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.