DTDs and XML schemata describe the vocabulary and structures that may appear when a document conforms to a given schema. Applications check documents against a schema or DTD and process the documents only if they pass the inspection. DTDs provide a definition of what the structure of data in an XML document should look like, while schemata also provide constraints to which documents must conform to be considered valid.
With the XML 1.0 recommendation from the World Wide Web Consortium (W3C), we're offered the DTD schema language that provides the ability to constrain XML documents to a specific XML schema. While the XML 1.0 DTD technology offers a solution, the upcoming XML schema language will likely play an important role in the future of XML and replace XML DTDs. Part of the problem is that XML schemata are in the candidate-recommendation phase of the W3C development process, and completing the specification may take some time.
The code for a DTD appears quite different from the code of a schema (See
"DTD and Schema Samples"). A quick look at the differences between the sample DTD and sample schema reveals that schemata provide much more in the way of data constraints than do DTDs.
Should you jump into the fray and use schemata, or should you stick with DTDs? The best practice is caution when using schemata. While schemata appear poised to replace DTDs, their support and use is not ubiquitous, so examine editors that support both DTDs and schemata. Several editors offer this support, with migration utilities to boot. Rational Software Corp.'s Rational Rose offers a script to convert UML-based DTDs to schemata, and Tibco Software's Turbo XML (with the inclusion of XML Authority) supports both DTDs and schemata with some interoperability. This ensures the ability to use the tool today--and tomorrow.
Although the specification is still just a recommendation, quite a few XML schema editors are available, many with the option to migrate DTDs to schemata. Some aren't much better than pencil and paper, but others are mature enough to be considered corporate-class solutions.
Pretty Pictures
A graphical method of manipulating the elements required to create a DTD or schema is a must-have. DTDs and schemata can be exceedingly complex, so graphical views are often necessary to examine the relationship between elements, as well as the attributes associated with elements.
Along with a graphical view of DTDs and schemata, most editors provide a method of viewing the DTD in a hierarchical manner. This "tree" view of a DTD or schema is invaluable as it lets developers view the nesting of elements within a DTD/schema (see "Sample Schema").
If your editor of choice does not offer the above features, go back to the drawing board. While simple DTDs and schemata can be edited manually with little error or confusion, the more complex DTDs and schemata necessary for defining the documents that will become an integral part of your e-business require more sophisticated methods.
Many DTD and schema editors can create DTDs/ schemata automatically from existing XML documents. Data Junction Corp.'s XML Junction, SoftQuad's XMetal and Turbo XML are among the editors that offer such functionality. If you've been manually editing DTDs/ schemata and want to move to a tool-based approach, this feature is priceless. Template-based creation of DTDs/schemata is also extremely useful. If you're starting from scratch, these templates can be used as a foundation for building your DTDs and schemata.
Because DTDs and schemata can grow increasingly complex, documentation is necessary. A good editor offers methods for documenting and reporting. DTDs do not provide for documentation, but the need for this feature was recognized and added to the XML schema specification.