tutorial and example
tutorial and example

XML Document Type Declaration, commonly it is called DTD. It is used to describe XML language absolutely. When we create DTD, we are creating a syntax rules for any XML documents that uses the DTD.


  • It start with <! DOCTYPE delimiter.
  • An element tells parser to parse document from specified root element.

Internal DTD

A DTD is referred to as an internal DTD if elements are declared within the XML files. Here declaration works independent of an external source.


Where root-element is the name of root element and element declaration is where you declare the elements.


External DTD

In external DTD elements are declared outside the xml file. The URL can point to either a local or remote file using relative and absolute refrencesrespectively. It means declaration includes information from the external source.


Where file name is the file with .dtd extension.


Example shows external DTD usage:

The content of the DTD file student.dtd is as shown:

We use system identifiers or public identifiers to indicate an external DTD.

System identifiers

It enable us to specify the location of an external file containing DTD declarations.

It contains keyword SYSTEM and a URI reference pointing to the location of the document.

Public identifiers

It provide the mechanism to locate DTD resources.

Here we can see, it begins with keyword PUBLIC, followed by specialized identifier. Public identifiers are used to identify an entry in a catalog. It follow any format, commonly used format is called Formal public identifiers.