How to choose between DTD and XSD How to choose between DTD and XSD xml xml

How to choose between DTD and XSD


It's probably important to learn DTDs as a separate exercise, just for the knowledge of how they work in case you encounter them somewhere else, and so that you can appreciate some of the things that XSD was trying to solve.

However, for your current purposes of describing an XML document, indeed stick to XSDs.

In addition to having a far richer feature set (like you mention, including data types and namespaces), they are also XML documents themselves, which can be really useful. Because they are XML, you can check their well-formedness and validity a lot easier, and you can write code that works with them like regular XML files (for instance, if you wanted to autogenerate code classes from a schema)


It really depends on how complicated the structure is that you need to setup.

If you need things like namespacing and datatypes, definitely go with XSD. If you just need a quick little schema to check against, DTD will give you faster performance since there is no XML parsing involved.

As I understand it, XSD is derived from DTD so understanding DTD will give a solid foundation for learning XSD, plus point out some of DTD's short comings.


It wouldn't hurt to understand the structure of a DTD (it'll help you better understand an XSD in the long run)...but you should use XSDs moving forward.