Comparing Schema Technologies

Although you haven't really learned much about the inner workings of DTDs and XSDs, you do understand that they represent two of the fundamental approaches to modeling XML document data. I alluded earlier that DTDs aren't as powerful as XSDs but there are advantages to DTDs when you consider that they have a long history and also are easier to create. On the other hand, XSDs offer considerable technical advantages over DTDs when you consider how much control they give you when nailing down the specifics of an XML data model. I'd like to take a moment to cover the specific differences between DTDs and XSDs so that you can better understand when to use each. Following is a list of the major differences between DTDs and XSDs:

  • DTDs are coded using a special language, whereas XSDs are coded in XML.

  • XSDs can be processed just like any other XML documents.

  • XSDs support a variety of data types (integer numbers, floating point numbers, Booleans [true/false], dates, and so on), whereas DTDs treat all data as strings or lists of strings.

  • XSDs present an open-ended data model, which allows you to extend custom markup languages and establish complex relationships between elements without invalidating documents. DTDs employ a closed data model that doesn't allow for much in the way of extensibility.

This list of differences obviously tips the scales in favor of XSDs. This is not just a matter of me being enamored with XML Schema. Keep in mind that XML Schema was created long after DTDs, so it stands to reason that it would address many of the weaknesses found in DTDs. Knowing this, you might think that it's a no-brainer choosing XSDs over DTDs to describe the data model for all of your XML documents. Although XSDs represent a more modern approach to XML data modeling, DTDs aren't quite dead yet. The one thing DTDs have going for them is the fact that they've been around for so long and are so widely accepted. If you think an inferior technology has never been able to survive solely on its longevity and widespread acceptance, think again. Look no further than your VCR to see such a technology in action; Betamax was known to be a more powerful technology but somehow the VHS standard stuck and the better technology lost. Even so, DTDs are being supplanted by XML Schema and other schema standards such as the newer RELAX NG schema technology.

One compelling argument for understanding DTDs is that many XML-based markup languages are still expressed as DTDs. So, if you plan on using any existing XML languages, you may need to be familiar with DTDs in order to understand how they work. The other point to keep in mind is that DTDs are actually very good at describing the structure of XML documents. The fact that XSDs do a better job is not enough to discount DTDs entirely.

by BrainBellupdated