alid XML documents follow a set of rules defined in a associated DTD. This Document Type Definition defines elements, attributes, and relationships between elements.
DTDs are saved in an ascii text file with the extension .dtd, like this:
When your XML document is processed, it is compared to its associated DTD to be sure it is structured correctly and all tags are used in the proper manner. This comparison process is called validation and is is performed by a tool called a parser.
Remember, you don't need to have a DTD to create an XML document; you only need a DTD for a valid XML document.
Before You Begin
There are a handful of terms you'll be hearing as you work with an XML DTD. Take a couple of minutes to become familiar with them before you begin. Click on any of the terms to see its definition.
A DTD is a way to ensure that an XML document uses elements correctly. It contains a set of rules. When your XML document is processed, it is compared to its associated DTD to be sure it is structured correctly and all tags are used in the proper manner.
- Always contains rules that define elements.
- Always contains rules that define the relationship between elements.
- May contain rules that define attributes for elements, althought not all elements have attributes.
- May contain rules that define entities.
- May may contain rules that define notations.