Forum Discussion

Kathleen_Leake's avatar
Kathleen_Leake
New Contributor
16 years ago

How to capture data in XML embedded in a CDATA string?

The input and response XMLs for our Web Service have XML data embedded in a CDATA string inside a SOAP Envelope.  Here's a sample of the response:


   
     
         <?xml version="1.0" encoding="UTF-8" standalone="yes"?><br /> <Envelope xmlns:ns2="http://xxxx.com/dms/fiom/apm/entity" xmlns="http://EOP.xxxxCorporation/Schema/ServiceRequestResponse"><br /> <Service Name="FIOM.APM.CreditApplication.Submit"><br /> <Operation><br /> <Response><br /> <Outcome Status="Success"><br /> <Tracking TimestampEnd="2009-05-01T14:51:35.847-05:00" TimestampStart="2009-05-01T14:50:54.675-05:00"/><br /> </Outcome><br /> <Result><br /> <ns2:creditApplicationId>2c95e67220d695740120fdbabbd30034</ns2:creditApplicationId><br /> </Result><br /> </Response><br /> </Operation><br /> </Service><br /> </Envelope>
         

     

   


I  need to pull out various fields from the response such as the Status and the creditApplicationID so that I can pass that data as input values in a subsequent request.  I'm very new to SoapUI, but I think I've determined that I need to use a property transfer for that purpose.  What I haven't figured out is how to go about getting the actual data out of the embedded XML.  Normally, I think I would use an XPath string, but the CDATA part has me baffled.

Can someone help?

Thanks.
  • Well, I've made progress.  I used a second XmlHolder to get the inner XML.  Now I'm able to capture the creditApplicationId value.  However I'm still having trouble with the Status attribute.

    My Groovy script has this:

        // get the inner XML data
        def innerXMLData = holderOuterXML["//processRequestReturn"]
        def holderInnerXML = groovyUtils.getXmlHolder( innerXMLData )

        // get the status to make sure it was successful
        responseStatus = holderInnerXML["//Outcome/@Status"]
        log.info( "response status (partial XPath) = " + responseStatus )

        responseStatus = holderInnerXML["/Envelope/Service/Operation/Response/Outcome/@Status"]
        log.info( "response status (full XPath) = " + responseStatus )


    The two log lines show:
        Wed May 06 12:04:32 PDT 2009:INFO:response status (partial XPath) = {}
        Wed May 06 12:04:32 PDT 2009:INFO:response status (full XPath) = {}

    Where am I going wrong?
  • After some fiddling around, I finally determined that the problem capturing the attribute value is that the default namespace ( xmlns="http://EOP.xxxxCorporation/Schema/ServiceRequestResponse" ) doesn't have a name attached to it.

    Some searching led me to a blog entry by Devakara ( http://groovyinsoapui.wordpress.com/200 ... n-soap-ui/ ) and I discovered that I could capture the value by using this statement:

    responseStatus = holderInnerXML["//ns1:Outcome/@Status"]

    My thanks to Devakara for his helpful blog.

    Kathy
  • Hello,

    I'm glad you were able to find the solution to your problem! Thank you for posting your findings here, as well, so that others may learn from it!

    Regards,
    Dain
    eviware support