Whatever happened to DTD?
November 18th, 2010There was a time when Document Type Definition (DTD) was all the rage. It was created as a set of declarations alongside Standard Generalized Markup Language (SGML), and helped contribute to the development of that language, Hyper Text Markup Language (HTML), and our very own Extensible Markup Language (XML). However, today DTD has been largely replaced by more modern schema languagesthe official XML Schema, RELAX NG, Schematron, ISO DSDL, and others. So what happened?It’s true that DTD has many benefits. For one, its age and inclusion in the XML 1.0 standard means that DTD declarations are supported across XML. DTD not only has less declarations than later languages, but also shorter ones, meaning it’s possible to see more language on a single screen. DTD allows for the declaration of SGML entity setsstrings associated with unique aliases or reserved words. Finally, namespaces weren’t around at the beginning of XML, so DTDs still define document types rather than namespace types. This means that all constraints are included in a single collection.Despite these advantages, though, other languages still largely overshadow DTDs. As mentioned above, DTDs have no namespace support, which is now a cornerstone of XML development. They are too simple to easily define complex structures, although some can be forced through by sacrificing clarity. Finally, since they use regular expression syntax, it is harder to use than an element-based syntax.XML Schema (also known as WXS or XSD) was published as a W3C recommendation in 2001, making it the first recommended schema after DTDs. It allows the content of an element to be validated against a data typea significant absence from DTDs. XSD uses a post-validation infoset to store information about a document, another of the many features which makes it especially useful for XML. It might be sad to say, but DTDs seem to truly be on their way out.