by Thomas Erl
 XML Core Technology
divider
 Understanding DTDs
 
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)>
]>
 

return to homepage


SOA: Principles
of Service Design

by Thomas Erl

An in-depth guide dedicated to service engineering with a thorough exploration of the design principles that comprise the service-orientation design paradigm (including a comparison with object-orientation).


Service-Oriented Architecture:
Concepts, Technology, and Design

by Thomas Erl

The first "how-to" guide to building SOA, providing coverage of WS-* specifications, .NET and J2EE platforms, and step-by-step processes for service-oriented analysis and design.
Service-Oriented Architecture:
A Field Guide
to Integrating
XML and Web Services

by Thomas Erl

The best-selling guide to service-oriented integration, providing hundreds of integration strategies and over sixty best practices.

For more information about either book, visit: www.soabooks.com

About SOA Systems

SOA Systems Inc. provides strategic SOA consulting services and offers a comprehensive SOA training program.

For more information see:

•  www.soasystems.com

•  www.soatraining.com



   
   
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>
</book>
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.

   
   
Home   Copyright © 1999-2007 SOA Systems Inc.