Forum Discussion

richie's avatar
richie
Community Hero
7 years ago

Event Handler To Remove CDATA In Response Doesn't Work? soapui.org/../working-with-cdata.html

Hi

 

 groovyguy's been helping me out with some CDATA troubles and I've been doing some reading and I've found a page in the soapui.org page that indicates you can create an event handler to remove the CDATA heading (doesn't remove the XML contained within the CDATA header) in the SOAP response XML.

 

The page is https://www.soapui.org/functional-testing/working-with-cdata.html

 

and the relevant detail is in section '6. An Event Handler To The Rescue'

 

Within the section it states to select the 'Events' option, select the 'RequestFilter.afterRequest' type, Event = RequestFilter.afterRequest

 

The script on the page is as follows:

 

def content = context.httpResponse.responseContent
content = content.replaceAll( "<!\\[CDATA\\[", "" )
content = content.replaceAll( "]]>", "" )

//log.info( content )

context.httpResponse.responseContent = content

I submitted the request expecting (desperately hoping) that the CDATA fragment would be removed and the tags within the CDATA would be split out into separate tags rather than a single string (like what the page indicates) but no luck - the tags all remain a single string within the CDATA.

 

Could anyone advise?

 

I've added a screenshot so you can see the Event Handler and the response XML 

 

Many thanks,

 

richie

3 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    One reason I didn't go down this route with my attempts to help are that this can inject false negatives for schema compliance tests, just FYI.

  • nmrao's avatar
    nmrao
    Champion Level 3
    richie,

    In the other thread, the sample response was shown. But, that does not have any cdata.

    Would you mind showing the response with CDATA?
    • richie's avatar
      richie
      Community Hero

      groovyguy - well that's not much help is it? :)

       

      rao -here ya go fella

       

      Soap response as follows:

      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
         <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <NS1:SyncVenueResponse xmlns:NS1="urn:CSMVenueSyncServicesIntf-ICSMVenueSyncServices">
               <return><![CDATA[<SyncVenueOutput>
        <Responses>
          <VenueSyncSuccesses>
            
          </VenueSyncSuccesses>
          <VenueSyncIgnores>
            <VenueSyncIgnore VenueID="AB123" SyncRequestedDateTime="20170829010000042"/>
          </VenueSyncIgnores>
          <VenueSyncErrors>
            
          </VenueSyncErrors>
        </Responses>
      </SyncVenueOutput>]]></return>
            </NS1:SyncVenueResponse>
         </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

       

      All this just cos I need to assert whetehr the request is successful or not and grab the VenueID to pass to a JDBC test step - all sounds simple - right? :)