Escape CDATA into another CDATA in XML

2

I have an XML inside a CDATA, I need to know how to escape the CDATA inside, so that the father does not cut himself when closing the first child.

<![CDATA[
   <?xml version="1.0"?>
       <API>
           <PARAMETRO1><![CDATA[TEXTO]]></PARAMETRO1>
           <PARAMETRO2><![CDATA[TEXTO]]></PARAMETRO2>
           <PARAMETRO3><![CDATA[TEXTO]]></PARAMETRO3>
       </API>
]]>

Thank you!

    
asked by Aleix Gallet Segarra 07.03.2017 в 13:40
source

1 answer

1

According to the specification, you can not escape ( W3C 2.7 CDATA Sections ).

What can be done is to close the current CDATA section with the characters ]] and reopen a new one that includes the > , so that it would be replaced:

]]>

for

]]]]><![CDATA[>

In your example:

<![CDATA[
   <?xml version="1.0"?>
       <API>
           <PARAMETRO1><![CDATA[TEXTO]]]]><![CDATA[></PARAMETRO1>
           <PARAMETRO2><![CDATA[TEXTO]]]]><![CDATA[></PARAMETRO2>
           <PARAMETRO3><![CDATA[TEXTO]]]]><![CDATA[></PARAMETRO3>
       </API>
]]>
    
answered by 07.03.2017 / 14:53
source