Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

DTD Introduction

DTD Introduction


A document type definition (DTD) defines the legal building blocks of an XML document. It uses a series of legal elements to define the structure of the document.

A DTD can be declared inline in an XML document or as an external reference.


Internal DOCTYPE declaration

If the DTD is included in your XML source file, it should be wrapped in a DOCTYPE declaration with the following syntax:

Example of an XML document with a DTD (open it in IE5 or later and choose View Source):

]>

Tove

Jani

Reminder

Don't forget me this weekend

Open this XML file in your browser and choose the "View Source" command.

The DTD above is explained as follows:


External document declaration

If the DTD is outside the XML source file, it should be wrapped in a DOCTYPE definition with the following syntax:

This XML document is the same as the one above, but has an external DTD: (click to open this file, and choose the "View Source" command.)

  Tove

  Jani

  Reminder

  Don't forget me this weekend!

This is the "note.dtd" file containing the DTD:


Why use a DTD?

With a DTD, each of your XML files can carry a description of its own format.

With a DTD, independent groups can consistently use a standard DTD to exchange data.

Your application can also use a standard DTD to validate data received from outside.

You can also use a DTD to validate your own data.