Home

 

DTDs and XML schemas

DTDs and XML schemas are both used to describe XML document structure; however, in recent years the acceptance of XML schemas has gained momentum. Both DTDs and XML schemas define the building blocks for XML documents, the elements, attributes, and entities.

XML schemas are more powerful than DTDs. Here are some of the advantages of XML schemas over DTDs:

They can define data types for elements and attributes, and their default and fixed values. The data types can be of string, decimal, integer, boolean, date, time, or duration.

They can apply restrictions to elements, by stating minimum and maximum values. For example, an age element might be restricted to hold values from 1 to 90, or a string value can be restricted to only hold one value from a specific list of values in a defined allowed list such as Fixed, Savings, or Loan. Restrictions can also be applied to characters and patterns of characters, for example, characters can be restricted to those from `a' to `z' and the length of the character string can be restricted to only three letters. Another restriction could be that the string can have a range of lengths, for example, a password must be between 4 and 8 characters.

They can define complex element types. Complex types can contain simple types or other complex types. Restrictions can be applied to the sequence and frequency of the occurrence of each type. Complex types can be used in the definition of other complex types.

XML schema documents, unlike DTDs, are actually XML documents. This implies that XML schema documents can be automatically checked for validity, and authoring XML schema documents is simpler for those already familiar with XML. Also, XML parsers do not have to be enhanced to provide support for DTDs. Transformation of XML schema documents can be carried out using Extensible Stylesheet Language Transformation (XSLT) documents and they can be manipulated using the XML Document Object Model (DOM).

Detailed information about DTD and XML schema can be found at:

http://www.w3.org/TR/2006/REC-xml-20060816/
http://www.w3.org/XML/Schema
ibm.com/redbooks