The document type declaration and DTDs:

The document type (DOCTYPE) declaration consists of an internal, or references an external Document Type Definition (DTD). It can also have a combination of both internal and external DTDs. The DTD defines the constraints on the structure of an XML document. It declares all of the document's element typesglossary, children element types, and the order and number of each element type. It also declares any attributes, entities, notations, processing instructions, comments, and PE references in the document.

The internal DTD:

<!DOCTYPE root_element [

Document Type Definition (DTD):
elements/attributes/entities/notations/processing instructions/comments/PE references

]>

Example:
<?xml version="1.0" standalone="yes" ?>

<!--open the DOCTYPE declaration - the open square bracket indicates an internal DTD-->
<!DOCTYPE foo [

<!--define the internal DTD-->
	<!ELEMENT foo (#PCDATA)>

<!--close the DOCTYPE declaration-->
]>

<foo>Hello World.</foo>

Rules:

The External DTD:

External DTDs are useful for creating a common DTD that can be shared between multiple documents. Any changes that are made to the external DTD automatically updates all the documents that reference it. There are two types of external DTDs: private, and public.

Rules:

"Private" External DTDs:

Private external DTDs are identified by the keyword SYSTEM, and are intended for use by a single author or group of authors.

<!DOCTYPE root_element SYSTEM "DTD_location">

where:
Example:
<!--inform the XML processor that an external DTD is referenced-->
<?xml version="1.0" standalone="no" ?>

<!--define the location of the external DTD using a relative URL address-->
<!DOCTYPE document SYSTEM "subjects.dtd">

<document>
	<title>Subjects available in Mechanical Engineering.</title>
	<subjectID>2.303</subjectID>
		<subjectname>Fluid Mechanics</subjectname>
		<prerequisite>
			<subjectID>1.001</subjectID>
			<subjectname>Mathematics</subjectname>
		</prerequisite>
		<classes>4 hours per week (lectures and tutorials) for one semester.</classes>
		<assessment>tutorial assignments and one 2hr exam at end of course.</assessment>
		<syllabus>
		Fluid statics. The Bernoulli equation. Energy equation. Momentum
		equation. Differential Continuity equation. Differential Energy equation.
		Differential Momentum equation. Dimensional Analysis. Similitude. Laminar flow.
		Turbulent flow. Lift and Drag. Boundary layer theory.
		</syllabus>
		<textbooks>
			<author>Foobar</author>
			<booktitle>The Study of Fluid Mechanics</booktitle>
		</textbooks>
</document>

The external DTD ("subjects.dtd") referenced in the example above contains information about the XML document's structure:

subjects.dtd:
<!--see Element Type Declarations for an explanation of the following syntax-->
<!ELEMENT document (title*,subjectID,subjectname,prerequisite?,classes,assessment,syllabus,textbooks*)>
<!ELEMENT prerequisite (subjectID,subjectname)>
<!ELEMENT textbooks (author,booktitle)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT subjectID (#PCDATA)>
<!ELEMENT subjectname (#PCDATA)>
<!ELEMENT classes (#PCDATA)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
<!ELEMENT syllabus (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT booktitle (#PCDATA)>

"Public" External DTDs:

Public external DTDs are identified by the keyword PUBLIC and are intended for broad use. The "DTD_location" is used to find the public DTD if it cannot be located by the "DTD_name".

<!DOCTYPE root_element PUBLIC "DTD_name" "DTD_location">

where:
"prefix//owner_of_the_DTD//description_of_the_DTD//ISO 639_language_identifier"

Example:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>A typical HTML file</TITLE>
</HEAD>
<BODY>
This is the typical structure of an HTML file. It follows the notation of the HTML 4.0
specification, including tags that have been deprecated (hence the "transitional" label).
</BODY>
</HTML>

Note:

The following prefixes are allowed in the DTD name:

Prefix:Definition:
ISOThe DTD is an ISO standard. All ISO standards are approved.
+The DTD is an approved non-ISO standard.
-The DTD is an unapproved non-ISO standard.

Combining Internal and External Document Type Definitions:

A document can use both internal and external DTD subsets. The internal DTD subset is specified between the square brackets of the DOCTYPE declaration. The declaration for the external DTD subset is placed before the square brackets immediately after the SYSTEM keyword.

Example:
<!--inform the XML processor that an external DTD is referenced-->
<?xml version="1.0" standalone="no" ?>

<!--define the location of the external DTD using a relative URL address - 
the open square bracket indicates an internal DTD-->
<!DOCTYPE document SYSTEM "subjects.dtd" [

<!--the markup in the internal DTD takes precedence over the external DTD-->
	<!ATTLIST assessment assessment_type (exam | assignment | prac)>
	<!ELEMENT results (#PCDATA)>

<!--close the DOCTYPE declaration-->
]>

subjects.dtd:
<!ELEMENT document (title*,subjectID,subjectname,prerequisite?,classes,assessment,syllabus,textbooks*)>
<!ELEMENT prerequisite (subjectID,subjectname)>
<!ELEMENT textbooks (author,booktitle)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT subjectID (#PCDATA)>
<!ELEMENT subjectname (#PCDATA)>
<!ELEMENT classes (#PCDATA)>
<!ELEMENT assessment (#PCDATA)>
<!ATTLIST assessment assessment_type (exam | assignment) #IMPLIED>
<!ELEMENT syllabus (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT booktitle (#PCDATA)>

Rules: