Forum Discussion

Vijay3's avatar
Vijay3
New Contributor
7 years ago

How to parse CData element in xml response and pass it to next request?

Want to retrieve atsToken from the below response:

<data contentType="application/x-www-form-urlencoded;charset=UTF-8" contentLength="53"><![CDATA[atsToken=DA:1501022300340:fmsBe51FV_TUmnJFj1nz5f77Jqg]]></data>

 

And pass it to the next request, I'm not sure what XPATH expression can be used here.

 

Do I have to use XPath expression or script to retrieve the data?

 

Thanks in advance.

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Vijay3,

     

    Looks you are using REST with xml format.

    And your data is little tricky as it is inside CDATA. And even that is not simple string or xml, it is again properties. And this type of sample does not appear to be present in the soapui samples of above reply link.

     

    You can quickly try it online demo how to extract the same.

     

    Here you go, add Script Assertion for the request test step which extracts the token and set it test case level, so that property expansion can be used where that is needed i.e., ${#TestCase#ATS_TOKEN}

     

     

    • Vijay3's avatar
      Vijay3
      New Contributor

      nmrao

       

      Thanks for the answer. 

       

      After adding Script assertion, I'm getting the below error: 

      "Content is not allowed in prolog."

       

       

      • nmrao's avatar
        nmrao
        Champion Level 3

        Vijay3,

         

        Hope you have seen the demo link where is working fine.

         

        So, now the thing to look at is are you getting the same xml structure as you saw in the link / previous posted by you? or  is it different?