Parallel Design


Creating structures that for different elements that are very similar to one another makes DTD easier to use and understand.


Authoring a document with complex structure can be difficult if there are many elements, and each of these elements has their own particular content models.


Any document that is large enough to be potentially difficult to learn.


Having consistency in the structure of document types makes document instances easier to learn and process.


For elements that are similar in function use structures that are as close to identical as possible.



<!ELEMENT Figure (Title, FigureBody, Number?)>
<!ATTLIST Figure height CDATA
width  CDATA
id     ID  #REQUIRED>

<!ELEMENT Table (Title, TableBody, Number?)>
<!ATTLIST Table height CDATA
width  CDATA
id     ID  #REQUIRED>

These two elements "Figure" and "Table" have very similar content and identical attribute lists. This makes it very easy for authors of the document. Once they have learned the structure of one of the elements, the other one will be easy to use. The more variation there is between the two, the easier it is to confuse the two structures.


The more consistent the structure of various elements is the easier it is to learn to use a document type. Subtle differences in structure can be particularly difficult to learn. If, for example, in the above example, one of the "id" attributes was IMPLIED and the other one was REQUIRED, this would be a difficult distinction to remember. Users would constantly need to refer to the documentation to remind them which element's id was required and which one wasn't.

Related Patterns

Often the parts of the structure that are the same between two elements can be represented as Flyweights. This will help ensure that the two structures remain similar even through revisions of the document type.

Known Uses

The DocBook (http://www.oasis-open.org/docbook/intro.html) DTD defines these four entities:

<!ENTITY % div.title.content
"title, subtitle?, titleabbrev?">

<!ENTITY % bookcomponent.title.content
"title, subtitle?, titleabbrev?">

<!ENTITY % sect.title.content
"title, subtitle?, titleabbrev?">

<!ENTITY % refsect.title.content
"title, subtitle?, titleabbrev?">

All four of the elements have identical content model. This helps enormously in learning the specifics of this DTD.


See Structuring XML Documents, Section 3.2.2.