I have an XML response as below:
<ns:Envelope xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
<ns:Body>
<ns:response xmlns:svc="http://...serviceNameSpace"
xmlns:ent="http://....entitiesNameSpace">
<ns:customer>
<ns:contact>
<ns:type>firstclass</ns:type>
<ns:email>kevin@....com</ns:email>
<ns:details>
<ns:name>Kevin</ns:name>
<ns:area>Networking</ns:area>
</ns:details>
<ns:address>
<ns:code>39343</ns:code>
<ns:country>US</ns:country>
</ns:address>
</ns:contact>
<ns:contact>
<ns:type>secondclass</ns:type>
<ns:email>john@...com</ns:email>
<ns:details>
<ns:name>John</ns:name>
<ns:area>Development</ns:area>
<ns:address>
<ns:code>23445</ns:code>
<ns:country>US</ns:country>
</ns:contact>
</ns:customer>
</ns:response >
</ns:Body>
I am trying this to iterate childnodes details and address to validate the response with the request properties. But I could assert email but couldn't go into details (name and area) and address (code and country). Below is the code I am using
import groovy.xml.*
def envelope = new XmlSlurper().parseText(messageExchange.responseContentAsXml)
def type = 'secondclass'
def emailAddress= ${properties#emailAddress}
envelope.'**'
.findAll { it.name() == 'contact' }
.findAll { it.type.text().contains(type) }
.each {
assert emailAddress== it.emailAddress.text()
}
Please help me in iterating the nodes details(name and area) and address (code and country) for assertion