(computer science) In Standard Generalized Markup Language, a file that specifies the tags in a particular document and the relationships among the fields that they represent. Abbreviated DTD.
| Sci-Tech Dictionary: Document Type Definition |
(computer science) In Standard Generalized Markup Language, a file that specifies the tags in a particular document and the relationships among the fields that they represent. Abbreviated DTD.
| 5min Related Video: Document Type Definition |
| Wikipedia: Document Type Definition |
Document Type Definition (DTD) is a set of markup declarations that define a document type for SGML-family markup languages (SGML, XML, HTML). A DTD is a kind of XML schema.
DTDs use a terse formal syntax that declares precisely which elements and references may appear where in the document of the particular type, and what the elements’ contents and attributes are. DTDs also declare entities which may be used in the instance document.
XML uses a subset of SGML DTD.
As of 2009[update] newer XML Namespace-aware schema languages (such as W3C XML Schema and ISO RELAX NG) have largely superseded DTDs. A namespace-aware version of DTDs is being developed as Part 9[1] of ISO DSDL. DTDs persist in applications which need special publishing characters such as the XML and HTML Character Entity References, which were derived from the larger sets defined as part of the ISO SGML standard effort.
Contents |
A Document Type Declaration associates a DTD with an XML document. Document Type Declarations appear in the syntactic fragment doctypedecl near the start of an XML document.[1] The declaration establishes that the document is an instance of the type defined by the referenced DTD.
DTDs make two sorts of declaration:
The declarations in the internal subset form part of the Document Type Declaration in the document itself. The declarations in the external subset are located in a separate text file. The external subset may be referenced via a public identifier and/or a system identifier. Programs for reading documents may not be required to read the external subset.
The following example of a Document Type Declaration contains both public and system identifiers:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
All HTML 4.01 documents are expected[by whom?] to conform to one of three SGML DTDs. The public identifiers of these DTDs are constant and are as follows:
The system identifiers of these DTDs, if present in the Document Type Declaration, will be URI references. System identifiers can vary, but are expected[by whom?] to point to a specific set of declarations in a resolvable location. SGML allows for public identifiers to be mapped to system identifiers in catalogs that are optionally made available to the URI resolvers used by document parsing software.
DTDs describe the structure of a class of documents via element and attribute-list declarations. Element declarations name the allowable set of elements within the document, and specify whether and how declared elements and runs of character data may be contained within each element. Attribute-list declarations name the allowable set of attributes for each declared element, including the type of each attribute value, if not an explicit set of valid value(s).
DTD markup declarations declare which element types, attribute lists, entities and notations are allowed in the structure of the corresponding class of XML documents.[2]
An Element Type Declaration defines an element and its possible content. A valid XML document contains only elements that are defined in the DTD.
Various key-words and characters specify an element’s content:
Examples:
<!ELEMENT html (head, body)> <!ELEMENT p (#PCDATA | p | ul | dl | table | h1|h2|h3)*>
An Attribute List specifies the name, data type and default value of each attribute associated with a given element type,[3] for example:
<!ATTLIST img id ID #IMPLIED src CDATA #REQUIRED >
There are the following attribute types:
A default value can define whether an attribute must occur (#REQUIRED) or not (#IMPLIED), whether it has a fixed value (#FIXED), and which value should be used as a default value ("…") in case the given attribute is left out in an XML tag.
Entities are variables used to define abbreviations; a typical use is user-readable names for special characters.[4] Thus, entities help to avoid repetition and make editing easier. In general, there are basically two different types:
Notations read the file format of unparsed external documents in order to include non-XML data in a XML document. For example a GIF image:
<!NOTATION GIF system "image/gif">
The XML DTD syntax is one of several XML schema languages.
A common misconception holds that non-validating XML parsers do not have to read DTDs, when in fact, the DTD must still be scanned for correct syntax as well as for declarations of entities and default attributes. A non-validating parser may, however, elect not to read external entities, including the external subset of the DTD. If the XML document depends on declarations found only in external entities, it should assert standalone="no" in its XML declaration. Identification of the validating DTD may be performed by the use of XML Catalogs.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE people_list SYSTEM "example.dtd"> <people_list> <person> <name>Njandu Varuthude</name> <birthdate>04/02/1977</birthdate> <gender>Male</gender> </person> </people_list>
An example of a very simple XML DTD to describe a list of persons might consist of:
<!ELEMENT people_list (person*)> <!ELEMENT person (name, birthdate?, gender?, socialsecuritynumber?)> <!ELEMENT name (#PCDATA)> <!ELEMENT birthdate (#PCDATA)> <!ELEMENT gender (#PCDATA)> <!ELEMENT socialsecuritynumber (#PCDATA)>
Taking this line by line:
people_list is a valid element name, and an instance of such an element contains any number of person elements. The * denotes there can be 0 or more person elements within the people_list element.person is a valid element name, and an instance of such an element contains one element named name, followed by one named birthdate (optional), then gender (also optional) and socialsecuritynumber (also optional). The ? indicates that an element is optional. The reference to the name element name has no ?, so a person element must contain a name element.name is a valid element name, and an instance of such an element contains "parsed character data" (#PCDATA).birthdate is a valid element name, and an instance of such an element contains parsed character data.gender is a valid element name, and an instance of such an element contains parsed character data.socialsecuritynumber is a valid element name, and an instance of such an element contains parsed character data.An example of an XML file which makes use of and conforms to this DTD follows. It assumes that we can identify the DTD with the relative URI reference "example.dtd"; the "people_list" after "!DOCTYPE" tells us that the root tags, or the first element defined in the DTD, is called "people_list":
<?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>
One can 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. For security reasons, they may also choose not to read the external DTD.
Alternatives to DTDs are available:
| This article's external links may not follow Wikipedia's content policies or guidelines. Please improve this article by removing excessive or inappropriate external links. (August 2009) |
This entry is from Wikipedia, the leading user-contributed encyclopedia. It may not have been reviewed by professional editors (see full disclaimer)
| DTD (set of rules for marking up a document in SGML) | |
| SGML (technology) | |
| UDDI (technology) |
| What types of documents can I get notarized? Read answer... | |
| What type of document is the Declaration of Independence? Read answer... | |
| How do you type exponents on a Word document? Read answer... |
| What is the definition of a judgment and conviction document? | |
| What is Definition of document control? | |
| What is a definition for a 'Bundle of documents'? |
Copyrights:
![]() | Sci-Tech Dictionary. McGraw-Hill Dictionary of Scientific and Technical Terms. Copyright © 2003, 1994, 1989, 1984, 1978, 1976, 1974 by McGraw-Hill Companies, Inc. All rights reserved. Read more | |
![]() | Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Document Type Definition". Read more |