- DTD, or Document Type Definition, and XML Schema, which is also known as XSD, are two ways of describing the structure and content of an XML document.
- DTD is the older of the two, and as such, it has limitations that XML Schema has tried to improve.
- The first difference between DTD and XML Schema is namespace awareness; XML Schema is, while DTD is not.
- Namespace awareness removes the ambiguity that can result in having certain elements and attributes from multiple XML vocabularies, by giving them namespaces that put the element or attribute into context.
- Part of the reason why XML Schema is namespace aware while DTDs is not is the fact that XML Schema written in XML, and DTDs not.
- Therefore, XML Schemas can programmatically process just like an XML document.
- XML Schema also eliminates the need to learn another language, as it written in XML, unlike DTD.
Another key advantage of XML Schema is its ability to implement strong typing.
- An XML Schema can define the data type of certain elements, and even constrain it to within specific lengths or values.
- This ability ensures that the data stored in the XML document is accurate.
- DTD lacks strong typing capabilities and has no way of validating the content to data types.
- XML Schema has a wealth of derived and built-in data types to validate content.
- This provides the advantage stated above.
- It also has uniform data types, but as all processors and validators need to support these data types, it often causes older XML parsers to fail.
- A characteristic of DTD that people often consider both as an advantage and disadvantage. And is the ability to define DTDs inline, which XML Schema lacks.
- This is good when working with small files, as it allows you to contain both the content. And the schema within the same document, but when it comes to larger documents, this can be a disadvantage. As you pull content every time you retrieve the schema.
- This can lead to the serious overhead that can degrade performance.