Understanding DTDs
by Thomas Erl

Through the use of Document Type Definitions you can define simple schemas for XML documents.

DTDs have been in use for a long time and, as a result, have established themselves as a core part of both the SGML and HTML landscapes. When designing schemas to represent XML data in enterprise application environments, the features offered by the DTD language may be insufficient. The need for more complex document structures and validation rules, and a larger selection of data types often require more sophisticated schema definition languages, such as the XML Schema Definition Language (XSD).

There are, however, situations where DTDs are appropriate. An entire section in Chapter 5 is dedicated to discussing the applicability of DTDs compared to XML schema definitions. Additionally, since DTDs are so established, you are bound to run into them when delving into the world of legacy integration. It is therefore worth your while to familiarize yourself with the basics of the DTD language.

Within a DTD you can declare element types and attributes, establish parent-child relationships between element types, and assign simple data types and validation rules. There are also techniques for utilizing predefined DTD attributes to simulate inter-element relationship constraints.

HTML, for instance, uses a standard DTD that declares each of its element types, parent-child relationships between element types, nesting rules, attributes, and rules that ensure that element and attribute data is valid.

In the XML world, DTDs are used in the same way, defining the XML document structure (element types and parent-child relationships) and all of the rules that govern document content. Unlike HTML, however, which supplies a pre-defined DTD with a fixed set of element types, XML documents and their corresponding DTD can be completely customized.

Even though DTD information can be embedded within an XML document, it is typically kept in a separate file to which XML documents link using a header statement as follows:

<!DOCTYPE book SYSTEM “book.dtd”>

Inside a DTD, the document structure is created through a series of element type declarations, which establish a hierarchy of elements. The DTD begins with a document type declaration that represents the root element. This declaration corresponds to the header statement added to the XML document.

<!DOCTYPE book [

Characteristics of each element, such as data types and parent-child relationships, are also established, as follows:

<!ELEMENT book (title, author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>

Additional element characteristics, such as attributes and validation rules can also be defined:

<!ATTLIST book CATEGORY (Fiction|Non-Fiction)>

Here, the book element was assigned an attribute called category, which has a validation rule limiting its possible value assignments to Fiction or Non-Fiction.

Finally, a closing statement for the DOCTYPE definition is added to complete the document.


The entire contents of this simple DTD file are displayed below:

<!DOCTYPE book [
<!ELEMENT book (title, author)>
   <!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>

A physical instance (in the form of an XML document) of the document type in the above DTD would appear as follows:

<?xml version=”1.0”?>
<!DOCTYPE book SYSTEM “book.dtd”>
<book category=”Fiction”>
  <title>Joy of Integration</title>
  <author>Joe Smith</author>

The example above only demonstrates a basic application of a DTD. The Document Type Definition syntax provides several features for the creation of more complex content models, including the use of entity references, and a series of keywords that provide processing instructions.

SOA Design Patterns by Thomas Erl
Foreword by Grady Booch
With contributions from David Chappell, Jason Hogg, Anish Karmarkar, Mark Little, David Orchard, Satadru Roy, Thomas Rischbeck, Arnaud Simon, Clemens Utschig, Dennis Wisnosky, and others.
Web Service Contract Design & Versioning for SOA by Thomas Erl, Anish Karmarkar, Priscilla Walmsley, Hugo Haas, Umit Yalcinalp, Canyang Kevin Liu, David Orchard, Andre Tost, James Pasley
SOA Principles of Service Design by Thomas Erl
Service-Oriented Architecture: A Field Guide to Integrating XML and Web Services by Thomas Erl
Service-Oriented Infrastructure:On-Premise and in the Cloud by Raj Balasubramanian, Benjamin Carlyle, Thomas Erl, Cesare Pautasso
Next Generation SOA:A Real-World Guide to Modern Service-Oriented Computing by Pethuru Cheliah, Thomas Erl, Clive Gee, Robert Laird, Berthold Maier, Hajo Normann, Leo Shuster, Bernd Trops, Clemens Utschig, Torsten Winterberg
SOA with .NET & Windows Azure: Realizing Service-Orientation with the Microsoft Platform by David Chou, John deVadoss, Thomas Erl, Nitin Gandhi, Hanu Kommalapati, Brian Loesgen, Christoph Schittko, Herbjorn Wilhelmsen, Mickey Williams
SOA Governance:
Governing Shared Services On-Premise & in the Cloud
by Stephen Bennett, Thomas Erl, Clive Gee, Anne Thomas Manes, Robert Schneider, Leo Shuster, Andre Tost, Chris Venable
SOA with Java by Raj Balasubramanian, David Chou, Thomas Erl, Thomas Plunkett, Satadru Roy, Philip Thomas, Andre Tost
Modern SOA Methodology: Methods for Applying Service-Orientation On-Premise & in the Cloud by Raj Balasubramanian, David Chou, Thomas Erl, Thomas Plunkett, Satadru Roy, Philip Thomas, Andre Tost
Cloud Computing: Concepts, Technology & Architecture by Thomas Erl, Zaigham Mahmood, Ricardo Puttini
Cloud Computing Design Patterns by Thomas Erl, Amin Naserpour

For more information about these books, visit: www.servicetechbooks.com

Arcitura Education Inc.
Arcitura Education Inc. is a leading global provider of progressive, vendor-neutral training and certification programs, providing industry-recognized certification programs for a range of certifications.
For more information:
SOA Certified Professional (SOACP)
The books in this series are part of the official curriculum for the SOA Certified Professional program.
For more information:
Cloud Certified Professional (CCP)
The books in this series are part of the official curriculum for the Cloud Certified Professional program.
For more information:
Big Data Science Certified Professional (BDSCP)
The books in this series are part of the official curriculum for the Big Data Science Certified Professional program.
For more information: