top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a CDATA section in XML?

+2 votes
374 views
What is a CDATA section in XML?
posted Feb 9, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

The term CDATA means, Character Data. CDATA are defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup.

The predefined entities such as <, >, and & require typing and are generally difficult to read in the markup. In such cases, CDATA section can be used. By using CDATA section, you are commanding the parser that the particular section of the document contains no markup and should be treated as regular text.

Syntax
Following is the syntax for CDATA section:

<![CDATA[
   characters with markup
]]>

The above syntax is composed of three sections:

CDATA Start section - CDATA begins with the nine-character delimiter <![CDATA[

CDATA End section - CDATA section ends with ]]> delimiter.

CData section - Characters between these two enclosures are interpreted as characters, and not as markup. This section may contain markup characters (<, >, and &), but they are ignored by the XML processor.

Example
The following markup code shows example of CDATA. Here, each character written inside the CDATA section is ignored by the parser.

<script>
<![CDATA[
   <message> Welcome to StudyHost </message>
]] >
</script >

In the above syntax, everything between and is treated as character data and not as markup.

CDATA Rules
The given rules are required to be followed for XML CDATA:

CDATA cannot contain the string "]]>" anywhere in the XML document.

Nesting is not allowed in CDATA section.

answer Feb 12, 2015 by Rahul Singh
...