I was wondering if there is any way to escape a CDATA end token (]]>
) within a CDATA section in an xml document. Or, more generally, if there is some escape sequence for using within a CDATA (but if it exists, I guess it'd probably only make sense to escape begin or end tokens, anyway).
Basically, can you have a begin or end token embedded in a CDATA and tell the parser not to interpret it but to treat it as just another character sequence.
Probably, you should just refactor your xml structure or your code if you find yourself trying to do that, but even though I've been working with xml on a daily basis for the last 3 years or so and I have never had this problem, I was wondering if it was possible. Just out of curiosity.
Edit:
Other than using html encoding...
>
as>
within CData to ensure embedded]]>
will not be parsed as CDEnd. It simply means it's unexpected and that&
must FIRST be encoded as&
too so that the data can be properly decoded. Users of the document must know to decode this CData too. It's not unheard of since part of the purpose of CData is to contain content that a specific consumer understands how to handle. Such a CData just can't be expected to be interpreted properly by any generic consumer. – BluepencilCDATA
was designed to allow anything: they are used to escape blocks of text containing characters which would otherwise be recognized as markup That impliesCDATA
too since it is also markup. But, in fact, you don't need the double encoding I implied.]]>
is an acceptable means of encoding aCDEnd
within aCDATA
. – Bluepencil