简体   繁体   English

如何使用 Xpath 定位子节点不包含属性的父节点?

[英]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 ,所以我们基本上是在做(以第二个例子为例):

  • Select all app s where...选择所有app所在的位置...
  • There is not a rdg child where...没有一个rdg孩子在哪里......
  • The wit attribute contains #R wit属性包含#R

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xpath:通过搜索父属性获取子节点 - xpath: getting child node by searching parent attribute Xpath:从父节点和子节点获取属性 - Xpath: To fetch attribute from parent node and child node XPath:获取子节点包含属性的节点如何在c#中选择具有和属性且父节点具有另一个属性的节点 - XPath : Get nodes where child node contains an attributeHow to select node that have and attribute and whose parent have another attribute in c# 如何使用xpath提取父节点的属性值? - how to extract attribute value of parent node with xpath? 使用父节点上的where条件获取XML子节点的属性值 - get attribute value of XML child node with where condition on parent node XPATH / XSLT:选择父节点的属性与另一个节点的属性匹配的节点 - XPATH / XSLT: Selecting a node where the parent node's attribute matches the attribute of another node Xpath:如何结合这两个子节点得到父节点? - Xpath: How to combine these two child node to get parent node? 如何在Java中使用xpath在xml中查找节点值或属性并将其替换为其他值? - How do I use xpath in Java to find a node value or attribute in an xml and replace it with another value? XML 数据提取,其中并非所有父节点都包含子节点 - XML data extraction where not all parent nodes contain the child node XPath Select节点,其中存在具有给定属性值的子级 - XPath Select node where exists child with given attribute value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM