2017-09-05 126 views
0

我正在使用Xpath 1.0表达式来查询XML文档。 我的目标是将所有选定的节点输出到Jaspersoft报告中,该报告显示一个新页面以及每个Uid的相应数据。XPath多节点

这里是我的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表达式。因此,如果有一个wellUid“001”和一个wellUid“002”,那么应该只有两行返回来自Well,RigI​​nformation,Operation和ReportDaily的所有信息。

RigInformation没有wellUid,但确实有ReportInily也有的rigInformationUid。

这里是我的查询到目前为止,我已经试过......

//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

这应该让你开始,因为你迭代指定wellUid的:

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()]