Understanding XML Document Type Definitions
- Dissecting an XML Document Type Definition
- Using Document Type Definition Notation and Syntax
- Understanding Literals
- Declaring a NOTATION
- Creating ATTLIST Declarations
- Using Special XML Datatype Constructions
- Understanding the Difference Between Well-Formed and Valid XML
- Learning How to Use External DTDs and DTD Fragments
- Altering an XML DTD
- Getting Down to Cases
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.
NOTE
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 picturean important part, but a part nonetheless.