Content Type Label
Parameter entities are created to represent different types of values within a DTD.
DTDs provide limited type information for content of attributes and elements. Type information is often useful to have in a language.
Any time DTDs are used and it is useful to convey type information.
Expressing type information helps in creating understandable and maintainable DTDs.
Create parameter entities to represent different data types. These parameters can be used in attribute and element content descriptions.
The following DTD fragment is taken from a payroll system. The first line defines a parameter entity to represent a employee number type. In each place in the DTD where a employee number is needed as content, this parameter entity is used.
<!ENTITY % EmployeeNum "NMTOKEN">
<!ELEMENT Order (LineItem*)>
<!ELEMENT Employee (Name, Address)>
<!ATTLIST Employee Number %EmployeeNum;>
<!ELEMENT PayRecord (Period, Hours)>
<!ATTLIST PayRecord Employee %EmployeeNum;>
This pattern does not change the structure or constraints of the documents that are instances of the DTD, but it does make the DTD easier to understand and maintain.
This pattern increases understandability of the DTD by documenting the intended use of the content types to readers of the DTD. Looking at the above example we can see that it becomes obvious that the Employee's Number attribute and the PayRecord's Employee attribute contain the same type of value. If they were both just NMTOKENs this may not have been as obvious.
Maintainability of DTDs is increased by allowing all related content types to be changed from a single place. For instance, in the Examples section above if the company this payroll system was created for merges with another company, and the employee numbers from the new company can contain a space, the "NMTOKEN" attribute type is no longer valid. By changing the EmployeeNum parameter entity to "CDATA", all references to the employee number in the DTD can be changed.
This is an example of a
(http://www.w3.org/TR/xhtml1/) uses Content Type Labels extensively. For example:
<!ENTITY % URI "CDATA">
<!-- a Uniform Resource Identifier, see [RFC2396] -->
<!ENTITY % FrameTarget "NMTOKEN">
<!-- render in this frame -->
<!-- document base URI -->
<!ELEMENT base EMPTY>
href %URI; #IMPLIED
target %FrameTarget; #IMPLIED
The above excepts shows how Content Type Labels are used to make it clearer what is expected in the attributes of the
XML Modularization of HTML 4.0
(http://www.altheim.com/specs/xhtml/NOTE-xhtml-modular.html#sec2.2.1) by Murray Altheim explains the use of this pattern in XHTML.