iterate over a specific node in web service response using groovy
Hi,
I want to iterate over a specific node in web service response and store the data in an array. I tried to do some groovy scripting referring the samples in the forum. But the data doesn't get added to the array. I'm trying to loop over the attributeName node in the below sample. Kindly help to resole the issue.
My response is like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns4:GetAccountDetailsResponseMessage>
</ns4:account>
.....
<ns6:CustomCustomerAccount>
<ns3:attributes>
<ns3:attributeName>TELNUM</ns3:attributeName>
<ns3:attributeId>4232323</ns3:attributeId>
<ns3:attributeValue/>
</ns3:attributes>
<ns3:attributes>
<ns3:attributeName>SMSNUM</ns3:attributeName>
<ns3:attributeId>6565464</ns3:attributeId>
<ns3:attributeValue/>
</ns3:attributes>
</ns6:CustomCustomerAccount>
</ns4:account>
</ns4:GetAccountDetailsResponseMessage>
</soap:Body>
</soap:Envelope>
My Groovy scripting is as below:
import groovy.util.XmlSlurper
import com.eviware.soapui.support.XmlHolder
def WS_Data = context.expand( '${WS_GetAccountDetails#Response#declare namespace ns6.....GetAccountDetailsResponseMessage[1]/ns4:account[1]/ns6:CustomCustomerAccount[1]}' )
log.info("Start")
class AttributesInfo {
def attributeNameObj
}
List<AttributesInfo> AttributesInfoList = new ArrayList<>()
def WS_Results = new XmlSlurper().parseText(WS_Data)
def WS_attributes = WS_Results.Body.GetAccountDetailsResponseMessage.account.CustomCustomerAccount.attributes
// iterate over attributes data
WS_attributes.each { attributes ->
AttributesInfo attributeInfo = new AttributesInfo()
attributeInfo.attributeNameObj = attributes.attributeName
AttributesInfoList << attributeInfo
}
log.info (AttributesInfoList)
log.info("End")
Thanks!!