cancel
Showing results for 
Search instead for 
Did you mean: 

how to replace encoding information in xml

Highlighted
Occasional Contributor

how to replace encoding information in xml

Hi everyone,

I use this to replace redundancy using XML.

 

event>requestfilter.afterrequest

 

def content = context.httpResponse.responseContent
log.info content
content = content.replaceAll( "<!\\[CDATA\\[", "" )
content = content.replaceAll( "]]>", "" )
content = content.replaceAll("<\\?xml version=\"1.0\" encoding=\"iso-8859-9\"\\?>","")
log.info content
context.httpResponse.responseContent = content

 

Code replace CDATA but does not replace("<\\?xml version=\"1.0\" encoding=\"iso-8859-9\"\\?>","")

 

can you help me please...

 

xml response:

 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:alisverisBaslatResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="WsOtomotiv">
<return xsi:type="xsd:string"><![CDATA[<?xml version="1.0" encoding="iso-8859-9"?><XmlString><SONUC>1</SONUC><DURUM>0</DURUM><ACIKLAMA>Basarili Alisveris</ACIKLAMA><TRXNO>20061701011000001710</TRXNO><INDIRIM><YENIAVTUTAR>500,00</YENIAVTUTAR><DKID></DKID><DKAD></DKAD><DKKP></DKKP><DIPINDTUTAR>0,00</DIPINDTUTAR><URUNINDIRIMLIST><URUNINDIRIM><UKID>20200</UKID><UKAD>DIVAN</UKAD><UKKP>60</UKKP><URUNKOD>A</URUNKOD><UINDTUTAR>500,00</UINDTUTAR></URUNINDIRIM></URUNINDIRIMLIST></INDIRIM><KPAROPUAN>35,00</KPAROPUAN><TPAROPUAN>35,00</TPAROPUAN><HARCAMADURUM>1</HARCAMADURUM><IZINDURUM>1</IZINDURUM><KAYITDURUM>2</KAYITDURUM><VERDEKOD>18259294</VERDEKOD><ISYERIPUAN>0,00</ISYERIPUAN><ADSOYAD></ADSOYAD><URUNINDIRIMTARIHLIST><URUNINDIRIMTARIH><UKID>20200</UKID><UKAD>DIVAN</UKAD><BASLANGIC_TARIHI>18-01-2013</BASLANGIC_TARIHI><BITIS_TARIHI>30-12-2033</BITIS_TARIHI></URUNINDIRIMTARIH></URUNINDIRIMTARIHLIST></XmlString>]]></return>
</ns1:alisverisBaslatResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

16 REPLIES 16
Highlighted
Community Hero

Re: how to replace encoding information in xml

Hey @hrn83au,

It'll be your escaping that'll be the problem i'm guessing. Unfortunately my groovy escaping is rubbish...ive just looked at groovy escaping again and i still cant see why you need double \\ before the ? character in the xml declaration youre trying to remove from your soap body.
Ive used this find and replace plenty of times in my soapui projects but im not in front of my laptop right now. I'll post later with the correct escape sequence once im back in front of my laptop.

Cheers

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: how to replace encoding information in xml

hi @richie 

submitlistener.aftersubmit  works as below so I use it like this for requestfilter.afterrequest.

but submitlistener.aftersubmit   does not work automatically in test suite. 

we got support for this but we couldn't find a solution. (submitlistener.aftersubmit)

I thought I could use the after request as a solution. so I wrote here for support.

 

def content = submit.response.responseContent
content = content.replaceAll("<!\\[CDATA\\[", "")
content = content.replaceAll("\\]]>", "")
content = content.replaceAll("<\\?xml version=\"1.0\" encoding=\"iso-8859-9\"\\?>", "")
log.info (content)
submit.response.responseContent = content

 

I would really apreciate if you help

thanks.

Highlighted
Community Hero

Re: how to replace encoding information in xml

Hey @hrn83au,

You lost me a little. Are you saying the groovy ran fine with one handler, but didnt with the other handler?

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: how to replace encoding information in xml

Why to replace?


Regards,
Rao.
Highlighted
Occasional Contributor

Re: how to replace encoding information in xml

hi @richie 

yes.I write the details below.

 

1. SubmitListener.afterSubmit

    a. script is working when I run it manually. (I put the screenshot below)
a.JPG

   b. When I run the script automatically, the test suite doesn't work.

b.JPG

 

 

2. we tried to solve this problem using RequestFilter.afterRequest but it doesn't work at all (a and b).

 

I hope I haven't confused you more. I would be very happy if you could help me

Highlighted
Occasional Contributor

Re: how to replace encoding information in xml

hi @nmrao 

I don't use soap ui without replacing xml

Highlighted
Community Leader

Re: how to replace encoding information in xml

@hrn83au :

 

You can use below script to fetch data from cData tag, there is no need to replace the cData Tag

 

import com.eviware.soapui.support.GroovyUtils

def response = context.httpResponse.responseContent
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def v=groovyUtils.getXmlHolder(response)
def CDATAXml=v.getNodeValue("//*:return")
//it will print cdata
log.info CDATAXml
def data = new XmlParser().parseText(CDATAXml)
//it will print SONUC value
log.info data.SONUC.text()

 

Hope it will help you in resolving your issue.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Occasional Contributor

Re: how to replace encoding information in xml

hi @HimanshuTayal 

 

I did not understand where to use this script. can you specify that too.

 

thank you.

Highlighted
Community Leader

Re: how to replace encoding information in xml

@hrn83au :

 

You can add this in any groovy step or script assertion where ever you want to fetch CDATA value.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements