Forum Discussion

cmmi's avatar
cmmi
New Contributor
16 years ago

Remove CDATA / enable XPath assertions on payload

Hi.

I am currently evaluating SOAP UI Pro for Data Centered Testing of a XML Service. This service is accessible via a standard Web Service which acts as a wrapper. It has only one element per request/response.
My current problem is checking the payload of the response with the available XPath assertions. These do not work, as the response inner xml is display within a CDATA element, so XPAth only sees one element at this point. I already checked the forum here and what I could do to this point is removing the <xml> element at the start of the payload, but I could not get rid of CDATA tag yet. The available post mostly point to a no longer available blog entry at http://www.eviware.com/blogs/oleblog/?p=458, does anyone have the information contained there mirrored?

What I am looking for: Use script assertions on the payload xml to validate against a data source.

Raw Data View:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:executeResponse xmlns:ns2="http://****">
<return>
&lt;?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
&lt;SearchResponse>
...
&lt;/SearchResponse>
</return>


XML View:

<return><![CDATA[
<SearchResponse>
...
</SearchResponse>]]>
</return>


This is my SubmitListner.afterSubmit event code:

def content = submit.response.responseContent
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("search#Response")
def payload = holder.getNodeValue("//return[1]/text()")
def xmlid = '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>'
if (payload.startsWith(xmlid)) {
payload = payload.substring(xmlid.length(), payload.length()-xmlid.length())
}
holder.setNodeValue("//return[1]", payload)
holder.updateProperty()

log.info "event: " + holder.getXml()
submit.response.responseContent = holder.getXml()

1 Reply

  • cmmi's avatar
    cmmi
    New Contributor
    You know, the moment you start explaning your problems to others you sometimes get the right answer yourself. That's what happend here to me, below you can find my updated code which gives me the right answer now. There is only one slight issue. Running the test suit or test case will do just fine, but running only the test step gives me XPath assertion errors. Seems the "afterSubmit" event is not performed prior to the test step assertions in this case, can it be?


    if( submit.response == null )
    return

    def content = submit.response.responseContent
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def target = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel() + "#Response"
    def holder = groovyUtils.getXmlHolder(target)
    def payload = holder.getNodeValue("//return[1]/text()")
    def xmlid = '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>'
    if (payload.startsWith(xmlid)) {
    payload = payload.substring(xmlid.length(), payload.length())
    }

    holder.setNodeValue("//return[1]", payload)
    holder.updateProperty()
    content = holder.getXml()

    content = content.replaceAll(/<!\[CDATA\[/,'')
    content = content.replaceAll(/\]\]>/,'')

    submit.response.responseContent = content