Home » XML

CDATA (Character Data) in XML

In this article, we are going to learn about the CDATA (Character Data) in XML - its syntax, characteristics and example.
Submitted by Akash Kumar, on November 07, 2018


The Term CDATA basically refers to Character Data. In XML it is basically a block of texts or sentences that are not parsed by the parser and are treated as regular English text. It is difficult to read predefined entities such as <(),&(&) in the markup. For such situation, the concept of CDATA section introduced. In this section basically, we are commanding the parser that this particular section of XML document doesn’t contain markup and consider them as normal plain text.


Basic syntax of CDATA section as follows:

        code  with markup


CDATA section basically composed of three section these are as follows:

  1. CDATA Start section: CDATA starts with nine character delimiter that is <![CDATA[.
  2. CDATA End section: CDATA basically ends with three character delimiter that is ]]>.
  3. CData section: Characters written between Cdata Start section and Cdata End Section will be treated as characters, not as markup.

In this section, we basically deal with characters such as (, and &) but these characters are ignored by the processor of XML.


There are some basic rules to write CDATA section

  1. CDATA cannot contain the string ]]< anywhere in the XML document.
  2. We cannot put CDATA section under another CDATA section in other words we can say that nesting is not allowed in CDATA.

Usefulness of CDATA

These sections are useful when we cannot write XML code within the XML document.

For example, if a user wants to write a book with XSL which have an explanation about the use of an XML application, the XML markup which is going to appear in the book will be going to write in the source file in a CDATA section which will be ignored by the processor of XML.

Examples of CDATA

Following is an example of CDATA here each character written inside CDATA section is ignored by parser.

]] >

In the above example IncludeHelp!!! which is written inside the is treated as character not as markup.

Lets try to understand this using following examples. The following example basically stores the student information that is name.

<?xml version="1.0" encoding="UTF-8"?>
	<stu_info rollno="7">
					This is the CDATA area.
					We are basically storing special character that are recognize.

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.