How to unwrap CDATA text and make it part of outer XML?

dt
Observer

I'm having a response something like this,

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cbv2="urn:cbv2" xmlns:date="http://exslt.org/dates-and-times" xmlns:n="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Header />
  <SOAP-ENV:Body>
     <cbv2:processResponse>
        <cbv2:out>
           <![CDATA[<?xml version="1.0" encoding="UTF-8"?>
           <INProfileResponse>
              <Header>
                 <SystemCode>19</SystemCode>
                 <MessageText>SYS00019 Login Error. Please contact our Technical Support Center (888.839.0119) if you need assistance decoding the error messages.</MessageText>
                 <ReportDate>20180426</ReportDate>
                 <ReportTime>071738</ReportTime>
              </Header>
           </INProfileResponse>
           ]]>
        </cbv2:out>
     </cbv2:processResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I want to unwrap '<![CDATA' text to be unwrapped and put it under '<out>'. The output should look like this,

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:cbv2="urn:cbv2" xmlns:date="http://exslt.org/dates-and-times" xmlns:n="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Header />
  <SOAP-ENV:Body>
     <cbv2:processResponse>
        <cbv2:out>
           <INProfileResponse>
              <Header>
                 <SystemCode>19</SystemCode>
                 <MessageText>SYS00019 Login Error. Please contact our Technical Support Center (888.839.0119) if you need assistance decoding the error messages.</MessageText>
                 <ReportDate>20180426</ReportDate>
                 <ReportTime>071738</ReportTime>
              </Header>
           </INProfileResponse>
        </cbv2:out>
     </cbv2:processResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

One way is, I can do it through JS, just by replacing CDATA specific tags and reform the response. I'm not sure if we have any XSLT policy or some other way to make this happen. Eventually, I'm going to convert the response in JSON.

0 1 902
1 REPLY 1

Hi dt

Can you explain where did you get that message?

The CDATA encoding looks to me, to be a result of a problem or logic error during generation of the XML Document. What system is generating that message? Is it being generated from within Apigee Edge? If so, please give details how.

you asked:

How to unwrap CDATA text

but there is no guarantee that what is inside the CDATA wrapper is a valid XML document or element. There is no guarantee that the data is Xml-Safe. so it is not possible, in the general case, to simply "unwrap it".

You would need to do it "manually" I suppose, by extracting the text value and then testing to see if it is valid XML. Kinda messy.

Better to just correct the problem at the source - at the time the document is being generated.