我在SOAPUI中嘲笑肥皂服务。我在上下文中有一个对象列表。我想循环遍历此列表以构建XML响应
这样的事情:
响应脚本:
requestContext.list = [ new Person("name0"), new Person("name1") ]
requestContext.list = [ new Person("name0"), new Person("name1") ]
响应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>
知道我怎么能这样做吗?
由于
答案 0 :(得分:2)
您可以使用MarkupBuilder
,如下所示(省略SOAP信封)。有关详细信息,请参阅Groovy MarkupBuilder。
def expectedPayloadWriter = new StringWriter()
def expectedXml = new MarkupBuilder(expectedPayloadWriter)
expectedXml.MyResponse(xmlns: 'http://mywebservice'){
List{
requestContext.list.each{
Person{
Name(it.name)
}
}
}
}