cancel
Showing results for 
Search instead for 
Did you mean: 

How to parse XML contains escaped xml?

Highlighted
Occasional Contributor

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 5
Highlighted

Re: How to parse XML contains escaped xml?

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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️Please mark my answer as a solution if it was helpful
Highlighted
Occasional Contributor

Re: How to parse XML contains escaped xml?

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?
Highlighted

Re: How to parse XML contains escaped xml?

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

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️Please mark my answer as a solution if it was helpful
Highlighted
Occasional Contributor

Re: How to parse XML contains escaped xml?

It was also null
Highlighted

Re: How to parse XML contains escaped xml?

How are you getting to the attributes in your script? Can you please send it to us?

/Nenad
http://eviware.com

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️Please mark my answer as a solution if it was helpful
New Here?
Join us and watch the welcome video:
Top Kudoed Authors