An XML document that obeys the rules of the previous section is described as well-formed.
It is also possible to specify additional rules for the structure and content of an XML document, via a schema for the document. If the document is well-formed and also obeys the rules given in a schema, then the document is described as valid.
The Document Type Definition language (DTD) is a language for describing the schema for an XML document. DTD code consists of element declarations and attribute declarations.
An element declaration should be included for every different type of element that will occur in an XML document. Each declaration describes what content is allowed inside a particular element. An element declaration is of the form:
The elementContents can be one of the following:
An attribute declaration should be included for every different type of element that can have attributes. The declaration describes which attributes an element may have, what sort of values the attribute may take, and whether the attribute is optional. An attribute declaration is of the form:
The attrType controls what value the attribute can have. It can have one of the following forms:
The attrDefault either provides a default value for the attribute or states whether the attribute is optional or required (i.e., must be specified). It can have one of the following forms:
A DTD can be included directly within an XML document or the DTD can be located within a separate file and just referred to from the XML document.
The DTD information is included within a DOCTYPE definition following the XML declaration. An inline DTD has the form:
An external DTD stored in a file called file.dtd would be referred to as follows:
Paul Murrell
This document is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.