XML
documents must be well-formed or the browser will produce an error.
You may optionally specify validation rules, known as a document type
definition (DTD) that ensures all required elements are present; prevents
undefined elements from being included; enforces a specific data structure;
specifies element attributes and permissable values; defines default
values; and describes how the parser should access non-XML or non-text
content.
You can only have one DTD per XML document. To create a DTD, you must
enter a document type declaration in the XML document before any content.
While you can only have one DTD per XML document, you may divide the
DTD into internal and external subsets. The syntax for an internal subset
is as follows:
<!DOCTYPE root
[
declarations
]>
Root is the name of the document's root element and declarations are
the statements that comprise the DTD. The root attribut must match the
name of the root element or the parser will report and error. For external
subsets, the syntax is as follows:
<!DOCTYPE root SYSTEM "URL">
OR
<!DOCTYPE root PUBLIC "identifier" "URL">
Root is the name of the document's root element, identifier is a text
string that tells an application how to locate the external subset,
and URL is the location and filename of the external subset. The PUBLIC
form is used when the DTD has to be limited to an interanl system or
when the XML document is part of an old SGML application. Unless your
application requires a public identifier, you should use the SYSTEM
form for location the external subset. To include both an internal and
external subset, the syntax is as follows:
<!DOCTYPE root SYSTEM "URL">
[
declarations
]>
OR
<!DOCTYPE root PUBLIC "identifier"
"URL"
[
declarations
]>
The main advantage of using an internal subset is that it is easier
to compare the DTD to the document content. However, by using an external
subset, you can apply the same DTD to many XML documents that can be
shared amongst multiple authors. Internal subsets take precedence over
external ones if a conflict between them arises.