Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Document Type Definition


 Contents
A Document Type Definition (DTD for short) is a declaration in an SGML or XML document that specifies constraints on the structure of the document. It may be included within the document file, but is normally stored in a separate ASCII-text file. The syntax of SGML and XML DTDs is very similar but not identical.

Defining a DTD specifies the syntax of an application of SGML or XML, which may be a widely-used standard such as XHTML or a local application.

DTDs are usually employed to determine the structure of an XML or SGML document. A DTD will typically describe each allowable element within the document, the possible attributes and (optionally) the allowed attribute values for each element. Further, it will describe the nesting and occurrences of elements. Most of a DTD is usually composed of ELEMENT definitions and ATTLIST definitions.

1 Example

An example of a very simple XML DTD to describe a list of persons is given below:

Taking this line by line, it says:

  1. A "people_list" element contains of any number of "person" elements. The "*" denotes there can be 0, 1 or many "person" elements within the "people_list" element.
  2. A "person" element contains the elements "name", "birthdate", "gender" and "socialsecuritynumber". The "?" indicates that an element is optional. The "name" element does not have a "?", so a "person" element must contain a "name" element.
  3. A "name" element contains data.
  4. A "birthdate" element contains data.
  5. A "gender" element contains data.
  6. A "socialsecuritynumber" element contains data.

An example of an XML file which makes use of this DTD follows:

DOCTYPE people_list SYSTEM "example.dtd"> Fred Bloggs 27/11/2008 Male

The DTD given above requires a name element within every person element; the people_list element is also mandatory, but the rest are optional.

It is possible to render this in an XML-enabled browser (such as IE5 or Mozilla) by pasting and saving the DTD component above to a text file named example.dtd and the XML file to a differently-named text file, and opening the XML file with the browser. The files should both be saved in the same directory. However, many browsers do not check that an XML document conforms to the rules in the DTD; they are only required to check that the DTD is syntactically correct.

2 DTD criticisms and alternatives

While DTD support in XML tools is widespread due to its inclusion in the XML 1.0 standard, it is seen as limited for the following reasons:

Two newer XML schema languages that are much more powerful have achieved Recommendation status within the W3C and are increasingly favored over DTDs:

3 See also




Read more »

Non User