java - Xpath java - query with multiple conditions
问题描述
I am trying to extract from xml file names of all the people from "XYZ" group who voted AGAINST resolution with signature "A9-309". I have tried several queries by I have no idea how to combine these three conditions in one. Here is the structure of the file:
<Vote.Result Id="56" Date = "2021-3-21">
<Vote.text>
<a href="resolution-9-309-8">A9-309</a>recommendation 01
</Vote.text>
<Results.For>
<Group Identifier="ABC">
<Group.member id="102">George</Group.member>
<Group.member id="12">Diana</Group.member>
<Group.member id="27">Anna</Group.member>
<Group.member id="32">James</Group.member>
</Group>
<Group Identifier="XYZ">
<Group.member id="11">Frank</Group.member>
</Group>
</Results.For>
<Results.Against>
<Group Identifier="ABC">
<Group.member id="2">Gregory</Group.member>
<Group.member id="3">William</Group.member>
</Group>
<Group Identifier="XYZ">
<Group.member id="7">Theresa</Group.member>
</Group>
</Group>
</Results.Against>
</Vote.Result>
<Vote.Result Id = "89" Date = "2021-3-21">
.... etc.
e.g. this
//Vote.Result/Vote.text/a[contains(., 'A9-309')]/text();
would give me the vote, or
//Vote.Result/Results.Against/[@Identifier='XYZ']/Group.member/text();
would give me all members of XYZ group who voted AGAINST any vote.
How to combine these three? obviously, there are many <Vote.Results>
in the file, so this is why there is a problem.
Thank you for any help!
解决方案
Try:
//Vote.Result[Vote.text/a[contains(., 'A9-309')]]/Results.Against/Group[@Identifier="XYZ"]/Group.member/text()
to return one text node: Theresa
. Introduce a predicate (expression in square brackets) whenever you want to filter that particular axis of the expression. Predicates can be nested as shown in the example.
推荐阅读
- c - 有没有办法通过C代码在linux机器上设置特定的日期和时间
- python - 使用熊猫导入csv文件时出错-python
- ios - AVAudioSession.RouteChangeReason 未检测到连接的蓝牙耳机/耳机
- dynamic - 如何利用 Azure 数据工厂中的动态数据流来映射基于配置文件的查找表?
- python-3.x - 尝试使用 .after 在 tkinter 标签中循环函数的结果
- r - 为什么 scale_edge_width_identity(guide = "legend") 不起作用?
- javascript - 在 JavaScript 中,如何区分按下按钮和释放按钮?
- excel - ElseIf 语句未评估所有条件
- apache-spark - 在创建嵌套 pyspark 数据框架时重命名嵌套字段名称
- javascript - 如何从 React 中的公共文件夹设置背景图像(创建 React 应用程序)