Home > Articles > Web Services > XML

Understanding XML Document Type Definitions

  • Print
  • + Share This
In this sample chapter, author Lee Anne Phillips examines the XML Document Type Definition in detail, and discusses how they are constructed in whole and in part.
This sample chapter is excerpted from Special Edition Using XML, by Lee Anne Phillips.

Dissecting an XML Document Type Definition

A DTD (Document Type Definition) defines the form and syntax of XML language constructs. You create DTDs using simple rules that can seem far more complex than they really are. By creating or altering a DTD and making it available on the Web, you can effectively make a new or extended language understandable and usable by anyone whose browser supports XML. Most XML pages use public DTDs, which allow them to exchange data with other users in a standard format. Local extensions to a standard DTD allow the use of in-house structure extensions that are not relevant to other users.

A DTD is not needed to make a well-formed XML document. In fact, if your XML code is being generated automatically, you might reasonably opt to skip this step. To gain the benefits of being able to check your XML document for validity, however, you will need a DTD. And, to share your data easily over the Web, a DTD is a necessary step toward universality. A DTD allows you to capture and validate the full possibilities of your data structure instead of off the cuff improvisations when you want to slip in an optional field.

In a complex document, any particular document may use only a subset of the full possibilities defined by the document design. By identifying optional parts in a DTD, you retain control over their location in the structure even though they're not used in every case. At the same time, with the help of a DTD you can ensure that mandatory parts are always there, even though the document is well-formed without. A DTD allows you to share your document structure and the information that structure embodies across a wider audience than was previously possible.

You don't have to use proprietary data formats that require both parties to possess the same software, an enormous expense if you deal with many collaborators, customers, or vendors. Instead, you can publish your data structure where it can be freely viewed and used, or exchange one file with each vendor/customer, which furnishes a key to understanding how each field relates to the document as a whole.


A DTD is a precise data structure description that can be passed on to an automated tool. This raises the possibility of mechanizing the conversion of data from one form to another, or from one language to another, with minimal human intervention.

XML was designed in a way that allows XML processors and applications to view and use XML documents without access to a DTD, even if one exists. If a link goes down you don't want the data in a document to become worthless, after all. So a DTD is only a part of the picture—an important part, but a part nonetheless.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.