首页 > 解决方案 > 如何在 WSO2 EI 6.1.1 中从soap Payload 中检索元素

问题描述

我有以下来自 WSO2 DSS 端点的肥皂有效载荷。

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Response xmlns="http://ws.wso2.org/dataservice">
         <RestrictionCount>
            <count>1</count>
         </RestrictionCount>
      </Response>
   </soapenv:Body>
</soapenv:Envelope>

我想从上面的有效载荷中提取计数值。我通过使用在线 xpath 表达式工具尝试了类似“//RestrictionCount/count/text()”,它给了我结果,但是在编码中我尝试了同样的方法,使用下面的属性中介表达式,这对我不起作用

<property expression="//RestrictionCount/count/text()" name="count" scope="default" type="STRING"/>

谁能帮我解决这个问题?

标签: xpathsoapwso2esbwso2ei

解决方案


由于您正在处理名称空间,请使用local-name()选择元素:

<property expression="//*[local-name()='RestrictionCount']/*[local-name()='count']/text()" name="count" scope="default" type="STRING"/>

或者更好的是,在 XPath 表达式之前正确声明命名空间:

<property xmlns:ns="http://ws.wso2.org/dataservice" expression="//ns:RestrictionCount/ns:count/text()" name="count" scope="default" type="STRING"/>

推荐阅读