【问题标题】:Read value from XML within another XML: Mule从另一个 XML 中的 XML 读取值:Mule
【发布时间】:2018-09-15 20:44:10
【问题描述】:

我正在进行 SOAP 网络服务调用,并得到以下响应。我想读取内部XML中的值,下面的XML中1234684中的值为12345684。

我能够使用 #[xpath3('//:processaResponse /return[2]')] 获取内部 XML,将其存储在流变量和 #[xpath3('/AckReg/DataArea/PRegistration/PRDet/Person/IDSet/:ID[@schemeName="aid"]/text()')] 中。
这在我尝试在线解析器时有效,但它不会读取 Mule 中的值。

有什么方法可以使用一个 XPath 提取 oa:ID 标签中的 1234684。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <ns3:TXID xmlns:ns3="http://a.d.r.test.com/"></ns3:TXID>
        <ns3:SESSIONID xmlns:ns3="http://a.d.r.test.com/"></ns3:SESSIONID>
    </soapenv:Header>
    <soapenv:Body>
        <ns3:processaResponse xmlns:ns3="http://a.d.r.test.com/" xmlns:ns2="http://p.r.test.com/">
            <return>Hi</return>
            <return>
                <?xml version="1.0" encoding="UTF-8"?>
                <AckReg
     xmlns="http://www.test.com/e/1" languageCode="en-US" releaseID="normalizedString" systemEnvironmentCode="test" versionID="normalizedString"
     xmlns:oa="www.test.com/r/9"
     xsi:schemaLocation="http://www.test.com/a/1 ../test/test.xsd">
                    <Apa>
                        <oa:CreationDateTime>2018-04-05</oa:CreationDateTime>
                    </Apa>
                    <DataArea>
                        <Ack>
                            <OArea>
                                <o:Sender>
                                    <o:LID schemeAgencyName="testi" schemeName="Application ID">test</o:LID>

                                </o:Sender>
                            </OArea>
                            <OriginalActionVerb/>
                        </Ack>
                        <PRegistration>
                            <testids>
                                <IDSet schemeAgencyName="try">
                                    <oa:ID schemeName="abcid">1234684</oa:ID>
                                </IDSet>
                            </testids>
                            <PRDet>
                                <Person>
                                    <IDSet schemeAgencyName="try">
                                        <oa:ID schemeName="aid">1364561</oa:ID>
                                    </IDSet>
                                    <IDSet schemeAgencyName="enada">
                                        <oa:ID schemeName="Employee ID">adsad</oa:ID>
                                    </IDSet>
                                </Person>
                                <User>
                                    <oa:ID/>
                                </User>
                            </PRDet>
                        </PRegistration>
                    </DataArea>
                </AckReg>
            </return>
        </ns3:processaResponse>
    </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: xpath mule


    【解决方案1】:

    在您的表达式中,您在某些节点上缺少命名空间前缀或命名空间通配符 *: - 因此您的表达式失败。

    有什么方法可以使用一个 XPath 提取 oa:ID 标签中的 1234684。

    使用命名空间通配符可以组合您的两个部分表达式:

    //*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[@schemeName='abcid']/text()
    

    或者您可以使用带有命名空间通配符的绝对路径:

    /*:Envelope/*:Body/*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[@schemeName='abcid']/text()
    

    两种情况下的输出:

    1234684

    【讨论】:

      【解决方案2】:

      您甚至可以通过 groovy 脚本使用 XmlSlurper 类来获取相应的值。 root = new XmlSlurper(false, true).parseText(payload).declareNamespace('soapenv':"http://schemas.xmlsoap.org/soap/envelope/")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-19
        • 2016-06-20
        • 2011-06-28
        相关资源
        最近更新 更多