max1965
13 years agoContributor
extract data from soap response
I have the following soap response:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header/>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:acceptRequestResponse xmlns:m="http://vassv02:7001">
<response xsi:type="xsd:string"><![CDATA[<spml:batchResponse xmlns:spml='urn:oasis:names:tc:SPML:1:0' xmlns:dsml='urn:oasis:names:tc:DSML:2:0:core' requestID='20130218142616505' result='urn:oasis:names:tc:SPML:1:0#failure' error='urn:oasis:names:tc:SPML:1:0#customError'>
<spml:operationalAttributes>
<dsml:attr name='errorCode'>
<dsml:value>1403</dsml:value>
</dsml:attr>
<dsml:attr name='errorMessage'>
<dsml:value>Failed while running batch request</dsml:value>
</dsml:attr>
</spml:operationalAttributes>
<spml:deleteResponse requestID='20130218142616505-0001' result='urn:oasis:names:tc:SPML:1:0#failure' error='urn:oasis:names:tc:SPML:1:0#customError'>
<spml:operationalAttributes>
<dsml:attr name='id'>
<dsml:value>022100001</dsml:value>
</dsml:attr>
<dsml:attr name='errorCode'>
<dsml:value>1503</dsml:value>
</dsml:attr>
<dsml:attr name='errorMessage'>
<dsml:value>The provisioning was not deleted because corresponding cli, Billingcli or provisioningId was not found</dsml:value>
</dsml:attr>
</spml:operationalAttributes>
</spml:deleteResponse>
</spml:batchResponse>]]></response>
</m:acceptRequestResponse>
</env:Body>
</env:Envelope>
With the following groovy script i extract the first value of the errorCode (1403) field:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def response = context.expand( '${deleteRequest APT NAKED Sec#Response}' )
def holder = groovyUtils.getXmlHolder( response )
def cdata = holder.getDomNode('//response/text()').nodeValue
def holder2 = groovyUtils.getXmlHolder( cdata )
def errorCode = holder2.getDomNode('//dsml:attr[@name="errorCode"]/dsml:value/text()').nodeValue
log.info errorCode
How I should modify the script to extract the second errorCode value (1503) ?
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Header/>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:acceptRequestResponse xmlns:m="http://vassv02:7001">
<response xsi:type="xsd:string"><![CDATA[<spml:batchResponse xmlns:spml='urn:oasis:names:tc:SPML:1:0' xmlns:dsml='urn:oasis:names:tc:DSML:2:0:core' requestID='20130218142616505' result='urn:oasis:names:tc:SPML:1:0#failure' error='urn:oasis:names:tc:SPML:1:0#customError'>
<spml:operationalAttributes>
<dsml:attr name='errorCode'>
<dsml:value>1403</dsml:value>
</dsml:attr>
<dsml:attr name='errorMessage'>
<dsml:value>Failed while running batch request</dsml:value>
</dsml:attr>
</spml:operationalAttributes>
<spml:deleteResponse requestID='20130218142616505-0001' result='urn:oasis:names:tc:SPML:1:0#failure' error='urn:oasis:names:tc:SPML:1:0#customError'>
<spml:operationalAttributes>
<dsml:attr name='id'>
<dsml:value>022100001</dsml:value>
</dsml:attr>
<dsml:attr name='errorCode'>
<dsml:value>1503</dsml:value>
</dsml:attr>
<dsml:attr name='errorMessage'>
<dsml:value>The provisioning was not deleted because corresponding cli, Billingcli or provisioningId was not found</dsml:value>
</dsml:attr>
</spml:operationalAttributes>
</spml:deleteResponse>
</spml:batchResponse>]]></response>
</m:acceptRequestResponse>
</env:Body>
</env:Envelope>
With the following groovy script i extract the first value of the errorCode (1403) field:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def response = context.expand( '${deleteRequest APT NAKED Sec#Response}' )
def holder = groovyUtils.getXmlHolder( response )
def cdata = holder.getDomNode('//response/text()').nodeValue
def holder2 = groovyUtils.getXmlHolder( cdata )
def errorCode = holder2.getDomNode('//dsml:attr[@name="errorCode"]/dsml:value/text()').nodeValue
log.info errorCode
How I should modify the script to extract the second errorCode value (1503) ?