我使用Xpath 1.0 Expression来查询XML文档。 我的目标是将所有选定的节点输出到Jaspersoft报告中,该报告显示一个新页面以及每个Uid的相应数据。
这是我简化的XML文档片段:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<modules>
<Operation>
<Operation>
<wellUid lookupLabel="Well992454">cf1</wellUid>
</Operation>
</Operation>
<RigInformation>
<RigInformation>
<rigName>RigName12345</rigName>
<rigInformationUid>rig005</rigInformationUid>
<rigManager lookupLabel="Manager554">554</rigManager>
</RigInformation>
<RigInformation>
<rigName>RigName4578945</rigName>
<rigInformationUid>rig001</rigInformationUid>
<rigManager lookupLabel="Manager2254879">2254</rigManager>
</RigInformation>
</RigInformation>
<Well>
<Well>
<wellUid>cf1</wellUid>
<wellName>Name 1</wellName>
</Well>
<Well>
<wellUid>cf2</wellUid>
<wellName>Name 2</wellName>
</Well>
</Well>
<ReportDaily>
<ReportDaily>
<wellUid>cf1</wellUid>
<rigInformationUid>rig001</rigInformationUid>
</ReportDaily>
</ReportDaily>
</modules>
</root>
我试图整理出一个显示wellUid下所有信息的XPath表达式。所以,如果有一个井&#34; 001&#34;和一个井&#34; 002&#34;,然后应该只有两行返回来自Well,RigInformation,Operation和ReportDaily的所有信息。
RigInformation没有wellUid,但有一个rigInformationUid,ReportDaily也有。
这是我迄今为止尝试的查询......
//ReportDaily/ReportDaily[wellUid = //Well/Well/wellUid] | //RigInformation/RigInformation[wellUid = //Well/Well/wellUid] | //Operation/Operation[wellUid = //Well/Well/wellUid] | //Well/Well[wellUid]
和
//Well/Well[wellUid and //ReportDaily/ReportDaily[wellUid = //Well/Well/wellUid and //Operation/Operation[wellUid = //Well/Well/wellUid and //RigInformation/RigInformation[rigInformationUid = //ReportDaily/ReportDaily/rigInformationUid]]]]
非常感谢任何帮助。
答案 0 :(得分:0)
这应该让你开始,因为你迭代了给定的井&#39;
root/modules/*/*[descendant::wellUid/text() = //Well/Well[1]/wellUid/text()] |
root/modules/*/*[descendant::rigInformationUid/text() = //descendant::rigInformationUid[preceding-sibling::wellUid/text() = //Well/Well[1]/wellUid/text()]/text()]