Questions tagged [cdata]

CDATA (literally, character data) is data that will not be parsed as markup in XML and SGML documents.

While technically "all text that is not markup constitutes the character data" of an XML document (and a similar definition applies for SGML), the term CDATA is typically used in the context of CDATA sections.

A CDATA section begins with the string <![CDATA[ and ends with the string ]]>. The data inside a CDATA section is not parsed as markup within an XML or SGML document - which can be useful when representing XML or SGML within an XML or SGML document:

<![CDATA[
  <html>
    <head>
      <title>This is not markup ...</title>
    </head>
    <body>
      <p>... and neither is this.</p>
    </body>
  </html>
]]>

A CDATA section may contain any sequence of characters except for the string ]]> (which would terminate the section). One way to work around this limitation is to terminate the CDATA section after the string ]] and then begin a new one immediately, starting with the final >. For instance,

<![CDATA[How to represent ']]]]><![CDATA[>' inside a CDATA section.]]>

is equivalent to

How to represent ']]>' inside a CDATA section.
1111 questions
1249
votes
13 answers

What does in XML mean?

I often find this strange CDATA tag in XML files: I have observed that this CDATA tag always comes at the beginning, and then followed by some stuff. But sometimes it is used, sometimes it is not. I assume it is to mark that…
dontWatchMyProfile
  • 45,440
  • 50
  • 177
  • 260
964
votes
15 answers

When is a CDATA section necessary within a script tag?

Are CDATA tags ever necessary in script tags and if so when? In other words, when and where is this: preferable to this:
brad
  • 73,826
  • 21
  • 73
  • 85
189
votes
6 answers

What is CDATA in HTML?

What is the use of CDATA inside JavaScript tags and HTML?
SexyMF
  • 10,657
  • 33
  • 102
  • 206
143
votes
10 answers

Is there a way to escape a CDATA end token in xml?

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…
Juan Pablo Califano
  • 12,213
  • 5
  • 29
  • 42
88
votes
5 answers

Should I use in HTML5?

I'm pretty sure sections can be used in XHTML5, but what about HTML5?
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
57
votes
5 answers

How to write CDATA using SimpleXmlElement?

I have this code to create and update xml file: '); $xml->title = 'Site Title'; $xml->title->addAttribute('lang', 'en'); $xml->saveXML($xmlFile); ?> This generates the…
quantme
  • 3,609
  • 4
  • 34
  • 49
48
votes
3 answers

Storing base64 data in XML?

How I can store base64 strings in XML? Do you use CDATA to store base64 strings in XML? Would it help as it allows use of < > within the strings? Is base64 configurable where you tell it not to use certain chars if they conflict with XML?
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
41
votes
10 answers

How to generate CDATA block using JAXB?

I am using JAXB to serialize my data to XML. The class code is simple as given below. I want to produce XML that contains CDATA blocks for the value of some Args. For example, current code produces this XML:
Shreerang
  • 638
  • 2
  • 7
  • 12
40
votes
11 answers

Html inside XML. Should I use CDATA or encode the HTML

I am using XML to share HTML content. AFAIK, I could embed the HTML either by: Encoding it: I don't know if it is completely safe to use. And I would have to decode it again. Use CDATA sections: I could still have problems if the content contains…
alberto
  • 553
  • 1
  • 4
  • 7
37
votes
4 answers

JSON - is there any XML CDATA equivalent?

I'm looking for a way that json parsing will take information as is (as if it was CDATA) - and not to try to serialize that. We use both .net and java (client and server) - so the answer should be about JSON structure Is there any way to achieve…
user1025852
  • 2,684
  • 11
  • 36
  • 58
31
votes
6 answers

what actually is PCDATA and CDATA?

it seems that a loose definition of PCDATA and CDATA is that PCDATA is character data, but is to be parsed. CDATA is character data, and is not to be parsed. but then someone told me that CDATA is actually parsed or PCDATA is actually not…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
28
votes
4 answers

Does Javadoc have an equivalent to ?

Unfortunately, there is no CDATA in HTML. This is a pity, because it would be perfect for adding javadoc comments that include XML, so you don't have to escape the < and >, for example: /** ]]>*/ However,…
13ren
  • 11,887
  • 9
  • 47
  • 64
26
votes
1 answer

Using CDATA inside another CDATA

I have this difficult situation where I need to use the CDATA tags inside another CDATA tags. The situation is simple to explain though. I have the following thing:
aborted
  • 4,481
  • 14
  • 69
  • 132
22
votes
6 answers

java.lang.IllegalStateException: CDATA tags may not nest

I've got a problem with an ajax request in a JSF page. When I click on the button, I get this exception: SEVERE: Servlet.service() for servlet Faces Servlet threw exception java.lang.IllegalStateException: CDATA tags may not nest at…
alinoe
  • 221
  • 1
  • 2
  • 3
1
2 3
74 75