XML technologies / XML / XML in a Nutshell / Document type definitions (DTDs)

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

XML is extremely flexible, but not all programs that read particular XML documents are equally flexible. Many programs can handle some XML applications but not others. For example, Adobe Illustrator can read and write Scalable Vector Graphics (SVG) files, but you would not expect it to understand a Platform for Privacy Preferences (P3P) document. Within a particular XML application, it is also important for documents to follow that application’s rules. In XHTML for example, li elements may only be children of ul or ol elements. Browsers may not know what to do, or may react incorrectly, if li elements appear in a blockquote or p element.

XML 1.0 offers a way out of this dilemma: the Document type definition (DTD). DTDs use a formal syntax that specifies exactly which elements may appear where in a document and what their content and attributes may be. A DTD can make statements such as “A ul element contains only li elements” or “Every element angestellter must have an attribute sozialversicherungsnummer ”. Different XML applications can use different DTDs to specify what is and is not allowed.

A validating parser compares a document with its DTD and lists every place where it departs from the DTD’s requirements. The program can then decide how to handle these violations. Some programs reject the document. Others may try to repair it or reject only the invalid element. Validation is an optional step in XML processing. A validity violation is not necessarily a fatal, unrecoverable error like a violation of well-formedness, although some applications may treat it as a fatal error.

  

  

 

 

 

back to top