Forum Discussion

mosleyma's avatar
14 years ago

Reading list of same elements into array for mock service

Hello-

I have searched the forums for answer to my question but have not found one that seems to help me. I am creating a mock service. One of the requests has the following xml structure.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.ape.com/webservice/UsNapSoap/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:AddMultipleItemstoCustomerReq>
<customerId>sadfsdf</customerId>
<!--1 to 200 repetitions:-->
<itemCode>ABC123</itemCode>
<itemCode>DEF456</itemCode>
.....
</v1:AddMultipleItemstoCustomerReq>
</soapenv:Body>
</soapenv:Envelope>

For example I am able to access the customerId element data in the request with the following

def req = new XmlSlurper().parseText(mockRequest.requestContent)
def custId = "${req.Body.AddMultipleSOCtoCustomerReq.customerId}"

However, with the <itemCode> I don't know how to I would be able to loop through the itemCodes in the request and read each value into an array. Any suggestions on how to do this?
No RepliesBe the first to reply