【问题标题】:How can i use XPATH in mule for Getting the XML node values?如何在 mule 中使用 XPATH 获取 XML 节点值?
【发布时间】:2014-01-26 01:07:50
【问题描述】:
#[xpath://soapenv:Envelope/soapenv:Body/out:notifications/out:Notification/out:sObject/urn:Summary] 

我正在使用上面的XPATH 代码来获取 XML 节点值。它不工作。如何纠正这一点。但以下代码工作正常。

<logger message="#[xpath('//*[local-name()=\'Description\']').text]&quot;" level="INFO" doc:name="Logger"/> 

我想使用第一种 XPATH 语法格式我该怎么做? 以下代码是我的 XML Dummy 数据。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:out="http://soap.sforce.com/2005/09/outbound" xmlns:urn="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header/>
   <soapenv:Body>
      <out:notifications>
         <out:OrganizationId>12345</out:OrganizationId>
         <out:ActionId>999999</out:ActionId>
         <out:SessionId>000000</out:SessionId>
         <out:EnterpriseUrl>ggggggg</out:EnterpriseUrl>
         <out:PartnerUrl>hhhhhhh</out:PartnerUrl>
         <!--1 to 100 repetitions:-->
         <out:Notification>
            <out:Id>iiiiiiii</out:Id>
            <out:sObject>
               <!--Zero or more repetitions:-->
               <urn:fieldsToNull>jjjjjjj</urn:fieldsToNull>
               <urn:Id>789076</urn:Id>
               <!--Optional:-->
               <urn:FirstName>aaaa</urn:FirstName>
               <!--Optional:-->
               <urn:LastName>bbbbb</urn:LastName>
            </out:sObject>
         </out:Notification>
      </out:notifications>
   </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: mule mule-studio mule-el mule-module-jpa


    【解决方案1】:

    首先,在第一个表达式中,您指的是一个名为 Summary 的元素,该元素在您的 XML 中不存在。

    现在,如果您想在 xpath 表达式中使用命名空间,则必须在名为 namespace-manager 的全局元素中声明它们:

    <mulexml:namespace-manager includeConfigNamespaces="false">
        <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/" />
        <mulexml:namespace prefix="out" uri="http://soap.sforce.com/2005/09/outbound" />
        <mulexml:namespace prefix="urn" uri="urn:sobject.enterprise.soap.sforce.com" />
    </mulexml:namespace-manager>
    

    使用上述内容并将Summary 替换为确实存在的东西,可以:

    <logger level="WARN" message="#[xpath://soapenv:Envelope/soapenv:Body/out:notifications/out:Notification/out:sObject/urn:Id]" />
    

    【讨论】:

    • 非常感谢.. 现在可以使用了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 2012-06-09
    • 2023-04-01
    • 1970-01-01
    • 2015-03-19
    相关资源
    最近更新 更多