Dtd Intro
# DTD Introduction
* * *
A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements.
A DTD can be declared inline inside 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 within a DOCTYPE declaration with the following syntax:
An XML document with an internal DTD (please open in IE5 or higher and select "View Source"):
<!DOCTYPE note >
Tove
Jani
Reminder
Don't forget me this weekend
[Open this XML file in your browser and select the "View Source" command.](#)
The DTD above is explained as:
* **!DOCTYPE note** (line 2) defines that this document is of type **note**.
* **!ELEMENT note** (line 3) defines the **note** element to have four elements: "to, from, heading, body"
* **!ELEMENT to** (line 4) defines the **to** element to be of type "#PCDATA"
* **!ELEMENT from** (line 5) defines the **from** element to be of type "#PCDATA"
* **!ELEMENT heading** (line 6) defines the **heading** element to be of type "#PCDATA"
* **!ELEMENT body** (line 7) defines the **body** element to be of type "#PCDATA"
* * *
## External Document Declaration
If the DTD is outside the XML source file, it should be wrapped within a DOCTYPE definition with the following syntax:
This XML document is the same as the XML document above, but it has an external DTD: ((#), and select the "View Source" command.)
Tove
Jani
Reminder
Don't forget me this weekend!
This is the "note.dtd" file containing the DTD:
* * *
## Why Use DTD?
With a DTD, each of your XML files can carry a description of its own format.
With a DTD, independent groups of people can agree on a standard DTD for exchanging data.
Your application can use a standard DTD to verify data received from an external source.
You can also use a DTD to verify your own data.
YouTip