What is a Document Type Definition (DTD)?


How does this technology work and how does it relate to other technologies currently used, such as DOM, Xpath, and Xquery?

I'm not looking for something quite thorough, an overview, how to run a DTD, and its relationship to other technologies can be exemplified with HTML or XML.

asked by anonymous 08.12.2016 / 21:14

3 answers


A document type definition (DTD) is a set of markup declarations that define a document type for an SGML (SGML, XML, HTML) family markup language.

(Source: Wikepedia )

That is, it tells the document what rules user agents should follow, and what is not allowed in a given version of an XML. It would be a way of telling them, what rules the document wants to follow and what rules the browser should use when parsing the document. For this reason, Choosing doctype influences the type of markup you're going to use.

A simple example of a DTO used to define an animal:

<!DOCTYPE animal [
   <!ENTITY header "Detalhe do animal">
   <!ELEMENT especie (#PCDATA)>
   <!ATTLIST tipoLocomocao (quadrupede | bipede) #required>
   <!ELEMENT alimentacao (#PCDATA)>

In this example, the item header was first set to Detalhe do animal . The data type #PCDATA means that it can be any text value. Already ATTLIST provides options for a specific element. In this case, the type of locomotion of animals is quadruped or biped.

This is a basic DTD that uses only a few data types. Document type definitions used for large XML databases can have thousands of rows and can include many other types of data. Fortunately, DTDs can be easily modified in a text editor whenever changes need to be made.

If you want to learn more, in this site , which I very well explained.

12.12.2016 / 18:01

This article from W3Schools is very enlightening in this sense:

What is a DTD?


What is a DTD?   The DTD is a Document Type Definition.


The DTD defines the structure and the legal elements and attributes of an XML document.


Why Use the DTD?   With a DTD, independent groups of people can agree on a standard DTD for interchanging data.


An application can use a DTD to verify that XML data is valid.

Can be used if your XML has specific sets of standards for your business or services.

I hope to have helped, hugs!

08.12.2016 / 22:41

Roughly and informally, a DTD is a "schema" for an XML document class. When using an XML parser with validation and informing the DTD to the parser, it can then accept an XML document as valid or deny it as invalid, according to the DTD informed.

I do not know if DTDs are still used, or if their use is acceptable or encouraged, because later the RELAX NG specification was created, which is a "real" (though simple) schema language for XML.     

17.12.2016 / 16:58