- Dissecting an XML Document Type Definition
- Using Document Type Definition Notation and Syntax
- Understanding Literals
- Declaring a NOTATION
- Creating ATTLIST Declarations
- Using Special XML Datatype Constructions
- Understanding the Difference Between Well-Formed and Valid XML
- Learning How to Use External DTDs and DTD Fragments
- Altering an XML DTD
- Getting Down to Cases
Using Document Type Definition Notation and Syntax
In general, most professional DTDs group their declarations by type and in a logical order, which makes them much easier to read and understand. The exact order is critical in some cases, but not in others, depending on whether the information is needed at the time a lookup table entry is made. Some expansions of entities are made only when used. Parameter entities are almost always needed, so they should usually come first.
TIP
To avoid having to think about what's needed and what isn't, it's a good habit to declare everything before using it. This makes it a little easier to find things as well, because you can usually look toward the top of the DTD to find an antecedent declaration.
You should make the root of your document tree the first ELEMENT, because many processors assume that the first element is the root. This mirrors the structure of well-formed XML to some extent, because the first tag encountered is always the root.
As a rule of thumb and for ease of use, ENTITY declarations should be made before ELEMENT and ATTLIST declarations that use them. ELEMENT declarations should be made before ATTLIST declarations that modify them. NOTATION declarations must be located prior to any use of the notation. Figure 3.1 shows an example of good XML coding practice.
Figure 3.1 This is a short example of well-organized XML DTD code.
Note that each section lists the different DTD declarations in a logical group, with each ATTLIST immediately following the ELEMENT it modifies and the rest arranged by type. This makes it easy to find each piece when you go looking for it.