【问题标题】:Default namespace and prefix in Proxy Service WSO2 ESB代理服务 WSO2 ESB 中的默认命名空间和前缀
【发布时间】:2012-11-02 14:44:05
【问题描述】:

我正在 WSO2 ESB 中开发代理服务。

使用此配置,我检索 xml Web 服务响应。响应使用默认命名空间,如下所示:

<enrich>
<source type="body" clone="true" />
<target type="property" property="soapXmlResponseReadCahceDataService" />
</enrich>

这是 xml 响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
<cacheServices **xmlns="http://cache.services"**>
<cacheService>
   <id>1</id>
   <xmlrequesthash>b1e97b67-1226-4b1d-9081-b2a140690efd</xmlrequesthash>
   <xmlrequestpayload>c</xmlrequestpayload>
   <xmlresponsepayload>d</xmlresponsepayload>
   <quantity>1</quantity>
   </cacheService>
</cacheServices>
</soapenv:Body> </soapenv:Envelope>

之后我需要获取元素数量

<property xmlns="http://cache.services" name="count" expression="//cacheServices/cacheService/quantity" />

WSO2 ESB 不允许你放置没有前缀的命名空间,而且我无法获得这个值。我可以获取这个值,因为 xml 响应没有命名空间前缀?

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:

    你能在属性中介器中试试这个 xpath 吗?

     <property name="count" expression="//*[name()='cacheServices']/*[name()='cacheService']/*[name()='quantity']" scope="default" type="STRING"/>
    

    或者,您可以通过添加任何命名空间前缀来使用它,因为您使用的是默认命名空间。

     <property xmlns:ns1="http://cache.services" name="count" expression="//ns1:cacheServices/ns1:cacheService/ns1:quantity" scope="default" type="STRING"/>
    

    【讨论】:

    • 感谢 Shelan,用这个表达式我可以得到这个值。在 wso2 数据服务中,是否可以使用前缀(xml 肥皂响应)更改默认命名空间以简化 xpath 表达式?
    • No 在数据服务中您不能指定前缀。我已经改进了答案,您可以按原样将其定义为简化。 (我在找到您问题的答案时了解到这一点。)谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 2013-02-17
    • 2013-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多