XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Design Patterns in XML Applications: Part II
by Fabio Arciniegas A. | Pages: 1, 2, 3, 4, 5, 6

XML Patterns in Element Definition


Table of Contents

Introduction
XMLable Pattern
Patterns in DTD Structures
Patterns in Element Definitions
A Little Advice
References

Arguably, the most widespread kind of XML patterns are those related to DTD content. These patterns are named solutions to recurring problems in the design of element types.

Not all patterns can or should be expressed in the same way. For instance, traditional behavioral patterns commonly have a different expression from data definition patterns. In this section, I opted to keep the layout for the patterns as defined by Liam Quin.

Running Text

Originator: Liam Quin

This pattern is included in its original formulation.

Synopsis

The Running Text Pattern is used for general textual content that may contain markup at the phrase, word, or symbol level, but not at the block level.

Actors

The Running Text Pattern has these participants:

  • Block Level Elements: The environment in which the pattern occurs.
  • Internal Markup: Markup that can occur within Running Text.
  • Running Text Definition: The implementation of Running Text.

Markup

Running Text is usually represented in a Document Type Definition as a Parameter Entity. The actual elements listed will vary from DTD to DTD, depending on the application; the Pattern specifies only the use of the entity RunningText:

<!ENTITY % RunningText
          '
            #PCDATA|Quote|Emphasis|MathML|Phrase|BibRef|
            FootNoteReference
          '
>

The pattern is used in the content model of other elements:

<!ELEMENT FootnoteBody
          (%RunningText;)*
>

The purpose of a single definition for Running Text is two-fold: firstly, to encapsulate the concept of generic running text, making the intent of a document type definition clearer; secondly, to ensure that the same set of basic elements is allowed everywhere text is allowed.

Additional elements can be added for a specific situation as follows:

<!ELEMENT PlaceName
          (%RunningText;|PlaceAlias|GridReference)*
>
Processing

This pattern does not require special processing. It is normally only seen by a validating XML processor.

Variations

In a complex Document Type Definition, it may be convenient to include other parameter entities in the definition of RunningText:

<!ENTITY % RunningText
          '
              #PCDATA|Quote|Emphasis|Phrase|BibRef|
              %elements.footnotes;|%elements.MathML;
          '
>

Marker Attribute

Originator: Fabio Arciniegas A.

Synopsis

The Marker Attribute Pattern is used when certain elements need to be marked via an attribute so they can be processed in a different way by a style sheet/program that recognizes the mark.

Actors

The Marker Attribute Pattern has three participants:

  • Marker Attribute: The marker is an attribute whose only purpose is to signal a binary state. If the attribute is present, the element must be treated differently.
  • Marked Element: The element that may contain the Marker Attribute.
  • Processing Application: The responsibility for performing the special action if the mark is encountered. This is usually encapsulated in a style sheet.
Markup

The markup necessary for this pattern is reduced to an attribute declaration:

<!ELEMENT video (title,artist,whatnot)>
<!ATTLIST video onSale  CDATA   #FIXED "yes">

and, possibly, the appearance of the attribute in the XML instance:

<video onsale="yes">
   ...
Processing

As mentioned above, a key characteristic of this pattern is outside of the XML document. The special behavior derived from the marking is usually achieved by means of a style sheet. The following example shows a simple case.

Example

A Marker Attribute for items on sale can be applied to the elements of a hypothetical DTD for videos as shown above. A simple XSLT style sheet can take care of a special presentation for the marked elements:

<xsl:if test="@onSale">
  <h4>
    <xsl:value-of select="artist"/> is on sale.
  </h4>
</xsl:if>
<!-- handle the rest of the element -->

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow