Forum Discussion

Sascha's avatar
Sascha
Occasional Contributor
16 years ago

How to parse XML contains escaped xml?

Hi,

I have a little problem. I receive a Soap Response not like the standard is. It looks like:

SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<?xml version="1.0"?><MessageResponse><Entity name="ORG_STRATEGY"><Property name="strategy_num" value="1048" type="INTEGER"/></Entity></MessageResponse>

As u see, there is one field called "return" and this includes escaped xml. How can I access this?

If I do:

def answer = holder.getNodeValue( "//return" )

I get the return string including this escaped String. I cannot access the elements in this string, because of the "<" ">"

Any Idea how to parse those responses?

An idea could be to do a search replace on the answer and give this back to the parser. But how would this work?

Thanks in advance
Sascha

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Create a second xmlHolder using the string with the escaped characters, and then use that to get to the information contained in it.

    I hope that helps,
    /Nenad
    http://eviware.com
  • Sascha's avatar
    Sascha
    Occasional Contributor
    Maybe I do something wrong in total.

    Here is my response:

    HTTP/1.1 200 OK
    Cache-Control: no-cache="set-cookie"
    Date: Thu, 05 Mar 2009 14:04:20 GMT
    Transfer-Encoding: chunked
    Content-Type: text/xml
    Set-Cookie: JSESSIONID=yTQJJvDXRByBQHhHfZm4FykKY0N9h34j5hSJ85G7sN2NnVz26spg!-342531176; path=/
    X-Powered-By: Servlet/2.5 JSP/2.1

    <?xml version="1.0"?><MessageResponse><Entity name="ORG_STRATEGY"><Property name="strategy_num" value="1050" type="INTEGER"/></Entity></MessageResponse>


    My Groovy Script

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "GetNextNum#Response" )
    def answer = holder.getNodeValue( "//return" )

    log.info( answer)
    answer=answer.replace("<","<")
    answer=answer.replace(">",">")
    log.info (answer)

    def holder2 = groovyUtils.getXmlHolder(answer)
    def answer2 = holder2.getNodeValue( "//MessageResponse");
    log.info(answer2)

    def node = new groovy.util.XmlParser(false,false).parseText(answer);
    def textNodes = node["//MessageResponse"]
    log.info(textNodes)


    My Loginfo

    Thu Mar 05 15:05:07 CET 2009:INFO:
    Thu Mar 05 15:05:07 CET 2009:INFO:
    Thu Mar 05 15:05:07 CET 2009:INFO:null
    Thu Mar 05 15:05:07 CET 2009:INFO:[]


    Why Null???? What is wrong in my thinking?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I think that you are getting the null because the MessageResponse node does not contain any text subnodes. Try accessing the properties in your script, and see if you can return them.

    Good Luck!
    /Nenad
    http://eviware.com