DTD – XML Building Blocks

Home » Scripting » XML » DTD – XML Building Blocks

The main building blocks of both XML and HTML documents are elements, but when we talk about XML the main blocks are:.

  • ♦ Elements
  • ♦ Tags
  • ♦ Attributes
  • ♦ Entities
  • ♦ PCDATA
  • ♦ CDATA

Elements

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

Examples of HTML elements are “body” and “table”. Examples of XML elements could be “note” and “message”. Elements can contain text, other elements, or be empty. Examples of empty HTML elements are “hr”, “br” and “img”.


Tags

Tags are used to markup elements.

A starting tag like <element_name> marks up the beginning of an element, and an ending tag like </element_name> mark up the end of an element.


Attributes

Attributes provide extra information about elements.

Attributes are placed inside the start tag of an element. Attributes come in name/value pairs. The following “img” element has an additional information about a source file:

<img src="juice.gif" />

“img” – name of the element

“src” – name of the attribute

“juice.gif” – value of the attribute


PCDATA

PCDATA means parsed character data.

The text found between the start tag and the end tag of an XML element.

PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.


PCDATA

CDATA also means character data.

CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.


Entities

CDATA also means character data.

Some characters have a special meaning in XML.

Entities are expanded when a document is parsed by an XML parser.

Entities examples:

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