The Document Type Definition (DTD)
There is another level of data validation in addition to a document being “well-formed.” You also want to be able to check that the document contains only elements that you expect, all the elements that you expect, and that they only appear where expected. For example, we know this is not a valid CD inventory entry:
<cd> <price>22</price> <qty>3</qty> </cd>
It's not valid because it doesn't have a title or artist field. Although we have three in stock, we can't say what it is three of.
What a DTD does
XML files therefore usually have a Document Type Definition or “DTD” that specifies how the elements can appear. The DTD expresses which tags can appear, in what order, and how they can be nested. ...