【问题标题】:XPath Multiple NodesXPath 多节点
【发布时间】:2017-10-26 20:39:54
【问题描述】:

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

这是我简化的 XML 文档的 sn-p:

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

我正在尝试整理一个 XPath 表达式,该表达式显示 wellUid 下的所有信息。所以如果有一个wellUid“001”和一个wellUid“002”,那么应该只有两行返回了所有来自Well、RigInformation、Operation和ReportDaily的信息。

RigInformation 没有 wellUid,但有 ReportDaily 也有的 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]]]]

任何帮助将不胜感激。

【问题讨论】:

    标签: xml xpath jasper-reports


    【解决方案1】:

    这应该让你开始,因为你迭代了给定的 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()]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 2014-03-26
      • 1970-01-01
      相关资源
      最近更新 更多