Forum Discussion

hrn83au's avatar
hrn83au
Occasional Contributor
5 years ago

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>

 

  • Hi hrn83au , I found your support case, looks like our Support team has a possible solution and now they are waiting on some files from you to make sure it works with your project. Please continue the investigation with the Support team and it would be great if you shared the final solution here with us too🙂 Thank you!

  • richie's avatar
    richie
    Community Hero
    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
    • hrn83au's avatar
      hrn83au
      Occasional Contributor

      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.

      • richie's avatar
        richie
        Community Hero
        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
      • nmrao's avatar
        nmrao
        Champion Level 3
        Didn't understand what you mean replace xml?