PCDATA - Parsed Character Data

It means decoded character data. For example;

<book>The Divan of Yunus Emre</book>

You have to write & < > instead of & < > inside the book element, otherwise you will act as if you are opening an element again and you will encounter an error.

In order not to encounter an error, we need to use CDATA.

CDATA - Character Data

It means character data. We use CDATA where PCDATA falls short. for CDATA;

<book>
<![CDATA[
Yunus <emre> Divan
]]>
</book>

It starts with <![CDATA[] and ends with ]]>.

Where do we use CDATA?

Scenario: There is a news site; The news site needs to be updated instantly, such as headlines, last minute, exchange rates, sports results. How can we update it using XML?

First of all, let's list the places that need to be updated on the site;

  • Site Title
  • Last minute
  • Cuff
  • Exchange
  • Sports Results

Let's create an XML suitable for this structure.

<?xml version="1.0" encoding="UTF-8"?>
<site update="01.01.2015 12:15">
<head>
<title></title>
</head>
<gov>
<headline></ headline>
<last minute></ last minute>
<quotes></quotes>
<sport></sport>
</body>
</site>

After creating the above tree structure, we will get an error if we add the HTML codes in the headline while filling in the necessary data.

We can solve this with CDATA.

<?xml version="1.0" encoding="UTF-8"?>
<site update="01.01.2015 12:15">
<head>
<title>Last Minute - News</title>
</head>
<gov>
<headline>
<![CDATA[
<li><img src="ilkaraba.jpg"></li>
<li><img src="ilkucak.jpg"></li>
<li><img src="ilkuydu.jpg"></li>
]]>
</headline>
<last minute>
<![CDATA[
<li>The first national vehicle working with boron was produced.</li>
<li>The first national aircraft was tested by the prime minister.</li>
<li>The first national satellite was launched from Kırşehir by TUBITAK.</li>
]]>
</last minute>
<exchange>
<![CDATA[
<div class="dollar">
x.xxxx
</div>
<div class="euro">
x.xxxx
</div>
<div class="bist/imkb">
x.xxxx
</div>
]]>
</exchange>
<sports>
<![CDATA[
<li>Incredibly talented kid.</li>
<li>Galatasaray management turmoil.</li>
<li>Shock transfer to the lantern.</li>
<li>Sponsor agreement from Beşiktaş.</li>
]]>
</sports>
</body>
</site>

In the update process, you can quickly complete the update process by breaking the XML data.