XML DTDs vs schemasTakeaway: Developers familiar with XML know that DTDs and schemas serve a similar purpose, but the debate over which one to use shows no signs of settling down. Find out what XML newsletter columnist Brian Schaffner thinks.
Every technology has its share of controversial topics, and XML is not immune to debate—especially when it comes to document type definitions (DTDs) and schemas. Both of these XML technologies perform similar functions, but the argument over which you should use rages on. Let’s look at some of the pros and cons of each.
The role of DTDs and schemas
Essentially, DTDs and schemas fulfill the same purpose: helping XML developers describe the structure and data within their XML documents. Without DTDs and schemas, it would be difficult to determine whether an XML document is valid in terms of it meeting certain structural and data type criteria.
The DTD or schema provides the XML parser with a description of what a particular type of XML document should look like. For example, it will say whether a <City> element can be contained within an <Address> element. It will also say how many <City> elements the parser should expect to find in the <Address> element, and it can describe the type of data within the element.
The DTD argument
DTDs, which have been around longer than XML, describe the type of document you're dealing with. When XML arrived as a specification, certain concepts were considered to help protect against mistakes within the document. One concept, validation, is the process of comparing an XML document to its DTD.