Use Parameter Entities
The natural extension of using entity references in an XML document is using parameter entities in a DTD. A parameter entity looks very much like an entity reference:
<!ENTITY % common.attributes
'id ID #IMPLIED
account CDATA #REQUIRED'
>
Here, a more strict textual replacement
occurs. In this case, the common.attributes
definition can be used to specify two attributes that most elements
in a constraint set should have. You can then define those elements
in the DTD, as shown in Example 5-2.
<!ELEMENT purchaseOrder (item+, manufacturer, purchaser, purchaseInfo)> <!ATTLIST purchaseOrder %common.attributes;> <!ELEMENT item (price, quantity)> <!ATTLIST item %common.attributes;> <!ELEMENT manufacturer (#PCDATA)> <!ATTLIST manufacturer %common.attributes;> <!ELEMENT purchaser (#PCDATA)> <!ATTLIST purchaser %common.attributes;> <!ELEMENT purchaseInfo (creditCard | check | cash)>
In Example 5-2, each element uses the
common.attributes parameter entity, which will be
converted into the string in the example (including the
id and account attributes).
This is done for each attribute list. And, like entity references,
changing the value of the parameter entity changes the definitions
for all elements. Again, this technique can be used to clean up the
organization of your DTDs.