Max
Max

Reputation: 708

Dynamic list in SOAPUI XML response


I'm mocking a soap service in SOAPUI. I have a list of objects in my context. I'd like to loop over this list to build the XML response.

Something like this :

Response Script :

requestContext.list = [ new Person("name0"), new Person("name1") ]

Response XML :

   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://mywebservice">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:MyResponse>
         <ws:List>
            <!-- Loop somehow over ${list} -->
            <ws:Person>
               <ws:Name>${list[i].name}</ws:Name>
            </ws:Person>
         </ws:List>
      </ws:MyResponse>
   </soapenv:Body>
</soapenv:Envelope>

Any idea how i could do something like this ?

Thanks

Upvotes: 0

Views: 1565

Answers (1)

dmahapatro
dmahapatro

Reputation: 50245

You can use MarkupBuilder as below (omitted the SOAP Envelope). Refer Groovy MarkupBuilder for in-depth details.

def expectedPayloadWriter = new StringWriter()
def expectedXml = new MarkupBuilder(expectedPayloadWriter)
expectedXml.MyResponse(xmlns: 'http://mywebservice'){
    List{
       requestContext.list.each{
          Person{
             Name(it.name)
          }
       }
    }
}

Upvotes: 2

Related Questions