EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Software Development Software Development Tutorials XML Tutorial PCDATA in XML

PCDATA in XML

By Priya PedamkarPriya Pedamkar

PCDATA in XML

Introduction to PCDATA in XML

XML Parsed Character Data (PCDATA) is defined as a parser reads a text in the XML document, means it parses every character and determines the exact meanings.  It’s a data definition that evolved from Standardized Generalized Mark-up Language to specify mixed content XML elements. The element content of DTD is defined as PCDATA which parse the content of the element which is a plain text and gives the result as mark-up. The Parsed Character data implies non-mark-up text and unable to differentiate between the data types like characters, int, float etc.

Syntax

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The common syntax of PCDATA is declared with the structure of DTD which is given below: The content model is

<!ELEMENT element-name (#PCDATA)>

Example:

  • <!ELEMENT balls (#PCDATA)>: Here a Balls element is considered to be some part of XML document. And the sample Xml of above DTD declaration line is given as
  • <balls> football </balls>: The string “football” would be defined as Parsed Character data

The above statement implies that the element balls contain data that is going to be parsed by the parser. PCDATA prefers to allow alphanumeric data.

How PCDATA works in XML?

Before we start with PCDATA it is necessary to learn the DTD concept of XML as PCDATA is declared herewith. The main benefit of DTD is to describe the structure of an XML file which has a set of elements, attributes, entities in it. The term entity references play a vital role in PCDATA. Some characters like (<, >,&, “, ‘  ) which are specified in XML syntax should be replaced by so-called forms called entity references to avoid mark-up tags confusion errors.PCDATA navigates through all the data’s in the XML documents.

For example, let us take a simple example and would see how the parser analyses each of the characters and mark-up tags.

Example #1

Below are some sample code:

Code #1

<analogies>
It makes students analyze the vocabularies and understands the relationships
between the mathematical terms. For example > 5 and <= 5.
</analogies>

The above Statement causes an error, as the parser reads the line 3 with (> 5) it assumes to be a beginning of an element as >, <, / these characters have a unique meaning in the mark-up terms. Hence, to include this it is better to use equivalent entities like &lt &gt. Care Must be taken while declaring Document elements in DTD as an element declaration imposing #PCDATA value is not provided for child elements. Next, PCDATA goes well with mixed content in DTD.

The sample usage is given below:

Code #2

<!ELEMENT p (#PCDATA|m|n)*>
Sample XML is given:
<p>Paragraph data <m/> with limited commas <m/> and more  text <n/></p>

Choosing PCDATA and an attribute in a DTD is to maintain an efficient data field in the document. In the earlier articles, we have seen different components of DTD and how they are declared with both inline and external files. Let’s see a brief sample with an Element tag associating PCDATA.

Code #3

<?xml version="1.0"?>
<Furniture>
<Sofas>soft</Sofas>
<Recliners> high</Recliners>
<Gliders>cushion</Gliders>
<Chairs>medium height</Chairs>
<Table>Accounting</Table>
</Furniture>
DTD
<!ELEMENT Furniture (Sofas, Recliners, Gliders, Chairs, Table)>
<!ELEMENT Sofas (#PCDATA)>
<!ELEMENT Recliners (#PCDATA)>
<!ELEMENT Gliders (#PCDATA)>
<!ELEMENT Chairs (#PCDATA)>
<!ELEMENT Table (#PCDATA)>
]>

The XML file above includes an element Furniture and this element has the following five child elements each hold text data. And the DTD below is used to validate the XML with parsers. Now, we are ready to declare the Furniture element which must contain (Sofas, Recliners, Gliders, chairs, Dressers). The declaration of all the child elements is very simple as it contains only one text. Therefore, all the remaining elements have #PCDATA models.

Code #4

<!ELEMENT Furniture (Sofas, Recliners, Gliders, Chairs, Dressers)>
<!ELEMENT Sofas (#PCDATA)>
<!ELEMENT Recliners(#PCDATA)>
<!ELEMENT Gliders (#PCDATA)>
<!ELEMENT Chairs(#PCDATA)>
<!ELEMENT Table(#PCDATA)>

Example #2

Below is the sample code mentioned:

Code

<!ELEMENT certificate_details (sur_name,first_name+,residence)>
<!ELEMENT sur_name (#PCDATA)>
<!ELEMENT first_name (#PCDATA)>
<!ELEMENT residence
(area,(city|district),(state|pincode),>
<!ELEMENT area (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT district (#PCDATA)>
<!ELEMENT state (#PCDATA)>

Examples to Implement PCDATA in XML

In this section, we shall see some examples by creating a simple DTD by defining some elements and entities which is useful for further identification purpose.

Example #1

Simple Example showing Internal DTD in XML with element text declared as PCDATA.

Code: air.xml

<?xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<!DOCTYPE Airline [
<!ELEMENT Airline (aname, country, class)>
<!ELEMENT aname (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT class (#PCDATA)>
]>
<Airline>
<aname>Alitalia</aname>
<country>Italy</country>
<class>passengers- business</class>
</Airline>

The DTD is a schema for XML document says that the element names text is Parsed Character data.

Output:

PCDATA in XML - 1

Example #2

PC-DATA works with an element declaring more children

Code: air.xml

<?xml version="1.0"?>
<!DOCTYPE restaurant [
<!ELEMENT restaurant (dishes*)>
<!ELEMENT dishes (#PCDATA)>
]>
<restaurant>
<dishes> pizza</dishes>
<dishes>Pasta</dishes>
<dishes>Do-Nuts</dishes>
</restaurant>

Here we have one element restaurant which is followed by a child element dishes and its text is declared as PCDATA to have different items on the dishes list.

Output:

PCDATA in XML - 2

Example #3

Implementing PCDATA in external DTD.

Code: addr.dtd

<!ELEMENT residence (aname,company,fax)>
<!ELEMENT aname (#PCDATA)>
<!ELEMENT company (#PCDATA)>
<!ELEMENT fax (#PCDATA)>

address.xml

<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<!DOCTYPE address SYSTEM "addr.dtd">
<residence>
<aname>Divya Mary</aname>
<company>EDUCBA</company>
<fax>(022) 013-5621</fax>
</residence>

Output:

external DTD

Example #4

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE grocerystore [
<!ELEMENT grocerystore (grocery+)>
<!ELEMENT grocery (Name, type+, category*, country?, mfd?, expdate?, price)>
<!ATTLIST grocery prodcode CDATA #REQUIRED>
<!ELEMENT Name    (#PCDATA)>
<!ELEMENT type   (#PCDATA)>
<!ELEMENT category (#PCDATA)>
<!ELEMENT country (#PCDATA)>
<!ELEMENT mfd   (#PCDATA)>
<!ELEMENT expdate  (#PCDATA)>
<!ELEMENT price    (#PCDATA)>
]>
<grocerystore>
<grocery prodcode="52486112">
<Name>Gerbers puffs</Name>
<type>Cereal</type>
<category>Children</category>
<mfd>2008</mfd>
<expdate>2009</expdate>
<price>11.79</price>
</grocery>
<grocery prodcode="65824575">
<Name>Breakfast  French Toast</Name>
<type>Cereals</type>
<category>Adults</category>
<mfd>2007</mfd>
<price>28.99</price>
</grocery>
<grocery prodcode="65214735">
<Name>Moong dhal</Name>
<type>All</type>
<type>Adults</type>
<type> Indian types </type>
<category>Indian Lentils</category>
<category>Icecream</category>
<country>USA</country>
<mfd>2010</mfd>
<expdate>2012</expdate>
<price>54.99</price>
</grocery>
</grocerystore>

Output:.

PCDATA in XML - 4

Conclusion

In very general terms, an efficient way to represent the text in DTD is by #PCDATA. Therefore, in this article we have introduced PCDATA with a small introduction, also we have done with the working principles in DTD with few implementations. And most of the features of XML language is pure with the attributes and elements which is defined here. With this enough background, you can create an application between a client and a server.

Recommended Articles

This is a guide to PCDATA in XML. Here we discuss an introduction to PCDATA in XML with appropriate syntax, working and respective examples. You can also go through our other related articles to learn more –

  1. XML Features
  2. XML Commands
  3. XML with CSS
  4. What is XML?
C++ PROGRAMMING Certification Course
38+ Hours of HD Videos
9 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ASP.NET Certification Course
149+ Hours of HD Videos
28 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
SQL - Everything in SQL
253+ Hours of HD Videos
51 Courses
6 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
SOFTWARE TESTING Certification Course
74+ Hour of HD Videos
13 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
XML Certification Course
 45+ Hours of HD Videos
11 Courses
Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more