XMLPatterns.com

Consistent Element Set

Abstract

Provide a set of elements which is consistently grouped together as the content models of a number of other elements.

Problem

Providing a flexible DTD structure could require authors to learn which element types can be used in content models of a variety of other element types. Having different content models for every element makes it difficult to authors to learn a DTD, and could make processing software more complex.

Context

Anywhere where a large number of elements can be sub elements of many different parent element types.

Forces

Large number of elements are difficult to use effectively. They can be difficult to learn and process.

Solution

Where sub elements appear, consistently provide the same set of elements in many different places. This reduces the learning requirements of authors. Usually the element set is defined with an entity parameter, and the entity parameter is referred to from each place the set needs to appear.

Examples

A DTD with inconsistent sets of elements in content model of various elements are difficult to learn how to use. For example:
        

<!ELEMENT Foo (A|B|C|E)*>
<!ELEMENT Bar (A|B|C|D)*>
<!ELEMENT Baz (A|C|D|E)*>

        
      
The next DTD is much easier to learn how to use, but some compromises must be made. It is often better to introduce consistency for the sake of ease-of-use.
        

<!ENTITY % content "A|B|C|D|E">
<!ELEMENT Foo (%content;)*>
<!ELEMENT Bar (%content;)*>
<!ELEMENT Baz (%content;)*>

        
      
Here the author has more flexibility, but there is more consistency. This can make it easier for processing software as well.

Discussion

The resulting structure provides easier to learn, consistent sets of elements. Providing consistent sets of elements is far easier for authors to learn. Some compromises might need to be made in the details of the structure to provide this consistency, but this is usually worth the price.

Related Patterns

Known Uses

In XHTML, there are element sets for block content, and inline content. The block content element set is used for all content that can be used at the paragraph level. Inline content is used consistently within paragraphs.