DTD Building Blocks : XML

In the last chapter we have learnt basics of XML DTD. In this chapter we will be learning the different parts of DTD or different building blocks of the XML DTD.

Main XML DTD Building Blocks :

Building BlockExplanation
ElementsMain nodes and main building block
AttributesExtra information about element.
EntitiesSpecial characters in XML
PCDATAparsed character data
CDATAcharacter data

A. XML Elements :

In HTML and XML, Elements are main building blocks.Consider the following XML document –

<Book pages="100">
   <name>Learn XML</name>

In the above example, XML elements are –

ElementName of the Element
Root ElementBook
Child Elementsname,author,type

Now each element in the XML document can contain either another element or data.

Name of the elementWhat data it stores ?
BookThis XML element stores 3 elements in it
nameThis XML stores Textual data
authorThis XML stores Textual data
typeThis XML stores Textual data

B. XML Attributes :

XML Attribute provides some kind of extra information about XML element. Attributes are kind of name and value pair which provides some information of element.

Consider the following example –

<Book pages="100" type="script">
   <name>Learn XML</name>

Now in this example –

<Book pages="100" type="script">
NameElement/Attribute ?Attribute value

C. XML Entities :

We know that XML tags are written inside the pair of < and >. So problem occures if we put these characters as textual data inside the XML.

So some characters which are having special meaning in the XML document are called as entities. XML provides list of following entities –

Entity ReferencesCharacter


PCDATA means parsed character data.CDATA means character data.
Generally used for ElementsGenerally used for Attributes
PCDATA is text that will be parsed by a parserCDATA is text that will not be parsed by a parser
Tags inside the text will be treated as markup and entities will be expandedTags inside the text will NOT be treated as markup and entities will not be expanded