Using XQuery in SoapUI property transfers

I've taken a few frustrating hours trying to work out how to transfer information out of a soap response into another soap request. As it took so long I thought I'd put this in case it helps someone.

It is easy enough to use the Property Transfer step in SoapUI to transfer single values like session keys, but when it comes to a list of result is is a little more challenging. It is possible to script the transfer using Groovy, however I thought it should be possible to use XPath.

The response is something similar to:

...
<results>
  <items>
    <item>
      <type>A1</type>
      <value>Orange</value>
    </item>
    <item>
      <type>A2</type>
      <value>Date</value>
    </item>   
  </items>
  <items>
    <item>
      <type>A1</type>
      <value>Lemon</value>
    </item>
    <item>
     <type>A2</type>
     <value>Apricot</value>
    </item>
  </items>   
</results>
...

Because the response can vary a transfer step is necessary to convert into the request:

...
<ids>
   <id>Lemon</id>
   <id>Orange</id>
</ids>
...

For our transfer we want to pull out all the A1 types from the response. Create a transfer step and check the XPath option, select the source information to be the correct response. The XPath is then:

declare namespace soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1=...local namespace...
 
<ns1:ids>
{
 for $id in //ns1:items[ns2:id = 'A1'] return <ns1:ids>{data($id/ns1:value)}</n13:ids>
}
</ns1:ids>

For the destination you need to put in the appropriate XPath expression for where the <ids> are to be inserted into the request. This XQuery will transfer all the values of type A1 only to the request.

BlogTag: 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.