In XML what is the difference between DTDs and Schema's?
-
See http://stackoverflow.com/questions/1490583/is-dtd-or-xml-schema-better – sourcedelica Sep 15 '11 at 03:53
-
When you talk of schemas, you need to be clear whether you are talking about schema languages in general (of which DTD is an example) or about the W3C XML Schema language (now called XSD) in particular. – Michael Kay Sep 15 '11 at 08:51
-
See also [What is difference between XML Schema and DTD?](http://stackoverflow.com/questions/1544200). – dma_k Mar 09 '12 at 10:43
2 Answers
Check out XML DTDs vs XML Schema for a good comparison and explanation.
The DTD provides a basic grammar for defining an XML Document in terms of the metadata that comprise the shape of the document. An XML Schema provides this, plus a detailed way to define what the data can and cannot contain. It provides far more control for the developer over what is legal, and it provides an Object Oriented approach, with all the benefits this entails.

- 41,170
- 10
- 86
- 110
DTD's are part of the XML specification itself. Schemas are not. There is only one DTD language; there are many schema languages, "XML Schema" and "Relax NG" being two common ones.
Most schema languages attempt to cover some limitations of DTD's (which are many), and my impression is that DTD's are quite out of favor for new applications. Yet, HTML is specified as a DOCTYPE definition, as are some parts of the EPUB specification. Their chief advantage at this point may be that a conforming XML processor should handle them, which you cannot say about any other schema language.

- 41,820
- 13
- 96
- 131