Forum Discussion

DW's avatar
DW
Occasional Contributor
7 years ago

CDATA problems with special characters

We have a 3rd party application that is returning the results within a CDATA string. I need to be able to get one of the tags in there (strQuoteNo) and then pass it for use in another request message but am having problems even getting at the tag.

 

I've searched all over and following the https://www.soapui.org/docs/functional-testing/working-with-cdata.html guide I have passed the whole CDATA string to a property.

 

declare namespace ns1='';
declare namespace rpc='http://www.w3.org/2003/05/soap-rpc';
declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
declare namespace saxon='http://saxon.sf.net/' ;
//ns1:rootCreateQuoteResponse/text()

 

The result is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><CreateQuoteResponse xmlns="webservices.quotation.company.com"><strQuoteNo>1234567</strQuoteNo><lngNoOfLives>13</lngNoOfLives><dblTotalBenefit>309033</dblTotalBenefit><dblFreeCoverLimit>65000</dblFreeCoverLimit><dteArd>2018-05-01</dteArd><DoclIst/><CommissionLevel><lngCommissionUnitVID>240</lngCommissionUnitVID><dblCommissionRate>12</dblCommissionRate><lngPremiumFrequencyVID>42</lngPremiumFrequencyVID><dblAnnualPremium>2696.14</dblAnnualPremium><dblModalPremium>224.6783</dblModalPremium><dblUnitRate>3.096</dblUnitRate></CommissionLevel></CreateQuoteResponse>

 

I think the problem is that this sting contains special characters as whatever I try next either results in 'null' or an error when trying to pass it to a new property.

 

Can anyone help advise here? Using the basic SoapUI rather than Pro, the idea is to then pass the quote number in to the next request message to issue the quote, which is also of CDATA format:

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <rootIssueQuoteRequest><![CDATA[<IssueQuoteRequest xmlns="webservices.quotation.company.com"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <Header>
  <strQuoteNo>1234567</strQuoteNo>
  <strUserId>ISSUEQUOTEUSER</strUserId>
 </Header>

</IssueQuoteRequest>]]></rootIssueQuoteRequest>
   </soapenv:Body>
</soapenv:Envelope>

  • JHunt's avatar
    JHunt
    Community Hero

    You can use a Groovy Script test step instead of a property transfer.

     

    First get hold of the response Xml:

     

    String xml = testRunner.testCase.getTestStepByName('someEarlierTestStep')
    .httpRequest.response.responseContent

    Get the data we want:

     

    String CDATA = new XmlSlurper().parseText(xml)
     .Body.rootIssueQuoteRequest.text()
     
    String myInnerStrQuoteNo = new XmlSlurper().parseText(CDATA)
     .Header.strQuoteNo.text()

    Then to make the script act like a property transfer, use something like:

     

    testRunner.testCase.setPropertyValue("someProp", myInnerStrQuoteNo)

     

    • DW's avatar
      DW
      Occasional Contributor

      Thanks for that. I tried it and it's reporting

       

      org.xml.sax.SAXParseException; Premature end of file for this line:

      String myInnerStrQuoteNo = new XmlSlurper().parseText(CDATA)

       

      I did try changing a few bits but I don't know the language that well so just ended up getting different errors of just nothing at all in the variable

  • JHunt's avatar
    JHunt
    Community Hero

    Oh yeah, sorry, to test my answer I had tried it against the request XML you posted, since you that was the only place you had given an example of a XML containing another XML in CDATA.

     

    Its looking for rootIssueQuoteRequest, returning null, and then trying to parse null.

     

    You just need to replace this:

     

    String CDATA = new XmlSlurper().parseText(xml)
     .Body.rootIssueQuoteRequest.text()

    with the appropriate path to the rootCreateQuoteReponse.

     

    Otherwise, I think there is some notation like this which is similar to XPath's //:

     

    String CDATA = new XmlSlurper().parseText(xml)
     .'**'.find {it.name == 'rootIssueQuoteRequest'}.text()