user3758298
user3758298

Reputation: 380

WSO2 ESB xpath problems

I want to use the following xpath

/Users/User/UserID

This does not work because the ESB adds a soap envelope and body around my xml, what is the correct xpath to use or how can I remove the soap envelope and body?

The xml is:

<?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>

EDIT:

This works when I try to log it outside of my iterate mediator

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

but when I try to log it inside the iterate mediator it returns nothing?

Upvotes: 1

Views: 2278

Answers (3)

user3758298
user3758298

Reputation: 380

Got this working by using the following

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

Upvotes: 1

Voicu
Voicu

Reputation: 17860

Try this:

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

You can read more on the predefined Synapse XPath variables here.

Upvotes: 0

user3714601
user3714601

Reputation: 1281

To access your elements you should go through envelope and body. Here is an example with switch mediator:

<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 corrected XPath expression

Upvotes: 0

Related Questions