2

If I'm building some XML and using <![CDATA[...]]>, how do I encode data that may include a ]]> substring? would it be ]]&gt;? I ask because I always thought CDATA content was literal content.

Jocelyn
  • 11,209
  • 10
  • 43
  • 60
Jeremy
  • 44,950
  • 68
  • 206
  • 332
  • Duplicate http://stackoverflow.com/questions/538163/how-do-i-write-the-literal-inside-a-cdata-section-with-it-ending-the-section – tehvan Feb 12 '09 at 06:48

4 Answers4

8

It's not terribly efficient, or easy to read, or anything, but an approach to this appears to be writing..

]]]]><![CDATA[>
Sciolist
  • 1,829
  • 14
  • 10
2

you can just use two cdata tags, the first one contains ]] and the second one contains >

Kim Stebel
  • 41,826
  • 12
  • 125
  • 142
-1

CDATA is literal content in a sense, but of course there has to be some way to mark the end of a CDATA block and whatever you choose is going to have to be represented in your string somehow.

When I had to deal with XML documents containing CDATAs inside another CDATA block like you seem to have to, I gave up and encoded the whole thing as Base64. The other side then extracts the text and decodes it.

Base64 is handy because it has common support and/or simple algorithms to code and decode ASCII strings into it in many languages, in my case C# and Javascript in an ASP.NET app.

Coxy
  • 8,844
  • 4
  • 39
  • 62
-2

Shouldn't entities work?

like this: &93;&93;&gt;

or, just one of them: ]]&gt;

93 is for latin1, you would need unicode entities if sending data in utf-8.

As a sidenote, there are other characters which are dissallowed in a CDATA-block aswell, some weird quotations and control-flow characters.

jishi
  • 24,126
  • 6
  • 49
  • 75