Skip to content

XML DTD Building Blocks

Understand the core components of XML documents (elements, attributes, entities, PCDATA, and CDATA) and how they form the foundation of XML DTD structure.

All XML documents are composed of elements, attributes, entities, PCDATA, and CDATA. These are the fundamental building blocks that make up XML documents.

Elements

Elements are the main building blocks of both XML and HTML documents.

Example:

<?xml version="1.0"?>  
<book>  
	<title>A Great Book</title>  
	<author>Tom Nolan</author>  
	<publisher>Tutorial Reference</publisher>  
</book>

where book, title, author, publisher are elements.

Attributes

Attributes provide extra information about elements.

Attributes are name-value pairs always placed inside the opening tag of an element.

Example:

<img src="myimage.png" />

where:

  • the name of the element is img;
  • the name of the attribute is src;
  • the value of the attribute is myimage.png

Entities

Some characters have a special meaning in XML, like the less than sign (<) that defines the start of an XML tag.

An entity is composed of three parts:

  1. An ampersand (&)
  2. An entity name
  3. A semicolon (;)
<!ENTITY entity-name "entity-value">

The following entities are predefined in XML:

Entity References Character
&lt; <
&gt; >
&amp; &
&quot; "
&apos; '

PCDATA

PCDATA means parsed character data.

PCDATA is text that will be parsed by the XML parser.

Tags inside the PCDATA will be treated as markup and entities will be expanded.

<!DOCTYPE book [  
	<!ELEMENT book (title,author,publisher)>
	<!ELEMENT title(#PCDATA)>
	<!ELEMENT author (#PCDATA)>
	<!ELEMENT publisher(#PCDATA)>
]>

CDATA

CDATA means character data.

Tags inside the CDATA text are not treated as markup and entities will not be expanded.

<![CDATA[
	...
]]>
Navigation