Does XSD replace DTD when going from SGML to XML?

Written by: Eliot Kimber Last Updated: 2006-08-28

=Question=

I know this may sound like a dumb question, but does xsd replace dtd when going from sgml to xml?

=Eliot Kimber answers=

While XML also has DTDs more or less as in SGML, I highly recommend not using DTDs and using XSD schemas instead. [I focus on XSD schemas instead of say, RelaxNG, for the simple reason that XSD schemas are the most fully integrated with the XML family of standards and with current tools. But the key reason for using schemas, that they are not syntactic components of documents, does hold for similar schema technologies. I have no particular opinion about the relative technical merits of, for example, XSD vs RelaxNG. At the moment it's VHS vs. BetaMax--it just doesn't matter because it's driven by what the market uses, not what's necessarily absolutely technically superior.]

(This is especially true if you are starting from scratch with XML or are just starting a migration from a legacy SGML system to XML--it won't take significantly more effort to go from SGML DTD to schema than from SGML DTD to XML DTD, so you might as well step up to schema. If you have a legacy XML system that is DTD based, obviously it will be harder (but not that hard) to migrate to the use of schemas.)

This is for several reasons:


 * DTDs are entities. Entities are bad. See previous rants here and elsewhere on this subject.
 * Schemas, because they are *not* syntactic components of documents are much more controllable then DTDs are.
 * It is the only *standard* way to enable validation and schema-aware processing of DTD-less XML documents.
 * XSD schemas are now widely supported in the generally-available XML infrastructure tool set, including Epic 5.x, xerces and all tools that use it), saxon, etc.
 * XSD schemas give you a lot more features for expressing rules.
 * Because they are in XML syntax, it is much easier to do processing of the schema for various purposes.

For more about my opinions on not using DTDs, see: http://xiruss-t.sourceforge.net/xml_usage_approach.html#schemas_only