【问题标题】:WSO2 ESB xpath problemsWSO2 ESB xpath 问题
【发布时间】:2014-07-30 12:11:38
【问题描述】:

我想使用下面的xpath

/用户/用户/用户 ID

这不起作用,因为 ESB 在我的 xml 周围添加了一个肥皂信封和正文,要使用的正确 xpath 是什么,或者我如何删除肥皂信封和正文?

xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <Users xmlns="http://ws.wso2.org/dataservice">
         <User>
            <UserID>a</UserID>
            <Username>a</Username>
            <Email>a</Email>
            <Password>a</Password>
         </User>
         <User>
            <UserID>a</UserID>
            <Username>a</Username>
            <Email>a</Email>
            <Password>a</Password>
         </User>
         <User>
            <UserID>a</UserID>
            <Username>a</Username>
            <Email>a</Email>
            <Password>a</Password>
         </User>
      </Users>
   </soapenv:Body>
</soapenv:Envelope>

编辑:

当我尝试在我的迭代调解器之外记录它时,这有效

//*[local-name() = 'Users']/*[local-name() = 'User']/*[local-name() = 'UserID']

但是当我尝试将它记录到迭代调解器中时,它什么也没返回?

【问题讨论】:

  • //Users/User/UserID 也不起作用

标签: xpath wso2 wso2esb wso2dss wso2developerstudio


【解决方案1】:

通过使用以下方法来解决这个问题

<property xmlns:int="http://ws.wso2.org/dataservice" name="uri.var.ID" expression="$body/int:User/int:UserID/text()" scope="default" type="STRING"/>

【讨论】:

  • 'int' 可能是数据服务提供的命名空间。即xmlns:int="http://ws.wso2.org/dataservice"。您可以在定义属性时在 UI 中添加命名空间,在 WSO2 中通常需要它们以使 XPATH 表达式正常工作。
  • 感谢您的精彩回答。
【解决方案2】:

要访问您的元素,您应该通过信封和正文。 下面是一个使用 switch 中介的例子:

<switch xmlns:ns="http://org.apache.synapse/xsd" 
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:int="http://ws.wso2.org/dataservice" 
        source="boolean(/soap:Envelope/soap:Body/int:Users/int:User/int:UserID/text() = 'string_to_compare'">
  <case regex="true">
     ....
  </case>
  <default/>
</switch>

UPD 更正了 XPath 表达式

【讨论】:

  • 使用下面的命令什么都不返回 org.apache.synapse/xsd" xmlns:soap="schemas.xmlsoap.org/soap/envelope" name="test" expression="/肥皂:信封/肥皂:正文/用户/用户/用户ID"/>
  • 似乎我错过了添加用户节点的命名空间。刚刚更新了答案,可以试试吗?
  • 仍然没有返回任何内容
  • 你可以试试“/soap:Envelope/soap:Body/int:Users/int:User/int:UserID”吗?
  • 我试过了,这也不起作用,我在网上找到了这个,这似乎有效 //*[local-name() = 'UserID'] ,但使用它会导致任何问题?
【解决方案3】:

试试这个:

<property name="yourParamName" expression="$body/Users/User/UserID" scope="default" type="STRING"/>

您可以阅读有关预定义 Synapse XPath 变量here 的更多信息。

【讨论】:

  • $body 给了我正文和它的内容,但是在它返回后添加 /Users 或其他任何东西
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-19
相关资源
最近更新 更多