Encyclopedia > DTD

  Article Content

Document Type Definition

Redirected from DTD

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.

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

 <!ELEMENT people_list (person*)>

 <!ELEMENT person (name, birthdate?, gender?, socialsecuritynumber?)>

 <!ELEMENT name (#PCDATA) >

 <!ELEMENT birthdate (#PCDATA) >

 <!ELEMENT gender (#PCDATA) >

 <!ELEMENT socialsecuritynumber (#PCDATA) >

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

 <?xml version="1.0" encoding="UTF-8"?>

 <!DOCTYPE people_list SYSTEM "example.dtd">
 <people_list>
   <person>
     <name>Fred Bloggs</name>
     <birthdate>27/11/2008</birthdate>
     <gender>Male</gender>
   </person>
 </people_list>

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 an ascii-text file named example.dtd and the xml file to a differently-named ascii-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.

External links

See also: Semantic Web



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Ocean Beach, New York

... density is 380.6/km² (967.1/mi²). There are 595 housing units at an average density of 1,640.9/km² (4,169.6/mi²). The racial makeup of the village ...

 
 
 
This page was created in 37.4 ms