pero on anything

CDATA Section within a CDATA (or “How to escape ]]> in CDATA?”)

Using CDATA to embed raw data within XML is a quite convinient feature. But the XML spec lacks the possibility to have a CDATA containing another CDATA or even the string ]]>.
So what happens if you put content like this within a CDATA section?


Just a ]]> test
]]>

Your XML writer or at least any descent parser will complain it is not valid XML! Even the color coding on this page reveals that ;)

What to do?

The easiest (and IMHO most compatible) way of handling this is to build multiple CDATA sections, like this:


Just a ]]>]]> ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">