Forum Discussion

max1965's avatar
max1965
Contributor
12 years ago

Extract value from XML response

I have the following XML response:

<ACA errorCode="5000">
<errorMessage/>
</ACA>

I need to write a groovy script to extract the errorCode value; someone can help me ?
  • Hi

    This will be a simple script that's do what you say:

    //xml processing libray
    import com.eviware.soapui.support.xml.XmlUtils
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

    //replace the <TestStepName> with the actual test name
    xmlResponseHolder = groovyUtils.getXmlHolder("<TestStepName>#ResponseAsXML")
    xmlBody = new XmlSlurper().parseText(xmlResponseHolder .getXml())

    errorCode = xmlBody.aca[0].@errorCode

    log.info errorCode

    this should do what you ask for
  • Thanks. I try your code, but did not works.

    This is the response:

    HTTP/1.1 200 OK
    Date: Wed, 06 Feb 2013 15:03:18 GMT
    Server: WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284
    Content-Length: 84
    Content-Type: text/html

    <?xml version="1.0" ?>
    <ACA errorCode="5000">
    <errorMessage></errorMessage>
    </ACA>

    This is the output from log.info:

    Wed Feb 06 16:03:18 CET 2013:INFO:

    The errorCode 5000 is not extract from the response message
  • I have tried also with ACA, but the errorCode is not extract from the response