Service Virtualization

 View Only
  • 1.  Data protocol to be used if XML Payload contains CDATA[]

    Posted Aug 10, 2016 06:00 AM

    We have  request XML containing CDATA in its payload. When I use XML data protocol or Generic XML Data protocol, CDATA section comes as a single argument in the VSI. Our requirement is to get each node of CDATA as separate arguments in VSI.If anyone has tried this scenario, please let us know the solution.



  • 2.  Re: Data protocol to be used if XML Payload contains CDATA[]

    Posted Aug 10, 2016 09:43 AM

    Did you try 'request data manager' protocol and try fetching arguments/fields you want ?



  • 3.  Re: Data protocol to be used if XML Payload contains CDATA[]
    Best Answer

    Posted Aug 10, 2016 05:15 PM

    Not sure if you solved your issue.  You could do this with a Scriptable DPH or a Custom DPH.

    - Get the body of the request as string

    - use String's replaceAll method to remove the CDATA tags

         ... = yourString.replaceAll("<\\!\\[CDATA\\[", "");

         ... = yourString.replaceAll("\\]\\]>", "");

         ... = yourString.replaceAll("&lt;", "<"); // incase cdata is encoded

    Substring the converted string in place of your CDATA or set the converted string into the body (lisa_vse_request.setBody( yourString) if you do not need the surrounding XML.  This of course depends on your requirement.

     

    NOTE: If the XML in the CDATA has a <!doctype> declaration, remove it using substring.

    Add the Scriptable DPH before the XML SOAP, Generic XML, RDM, XML DPH, etc. so your Arg List builds out to include the elements in your CDATA or play around with the order and type of XML parsers to get the desired Arg List.



  • 4.  Re: Data protocol to be used if XML Payload contains CDATA[]

    Posted Aug 11, 2016 06:26 AM

    Hi Joel

     

                Thank you very much for your guidance. We tried it using Scriptable DPH ad it worked for us.

     

    Regards

    Reshmi



  • 5.  Re: Data protocol to be used if XML Payload contains CDATA[]

    Posted Aug 11, 2016 08:27 AM

    Glad to hear that you got it working. 

     

    In case others look at this thread, additionally remove the XML declaration (<?xml version="1.0" ?>) if it exists in your CDATA or your parser will throw an exception.  XML declarations should occur once on the outer XML.