XMLPatterns.com

Head-Body

Abstract

When a large amount of metadata needs to be included in an element the designer may create two children for the element, one for the metadata and one for the body of the document.

Problem

Sometimes, an element has a large amount of metadata, and this metadata may need to be structured. In common XML usage, attributes are used for metadata. But with a large amount of metadata it is difficult for authors to include this information within attributes, which have limited structure. Including metadata as sibling elements of content elements leads to the potential to confuse the metadata and the data meant to be in the body of the element.

Context

There is a large amount of metadata about some piece of content. For example information about the title, creation date, and authors of a document should be included with the document, but this is not really information that belong in the body of the document.

Forces

A clear separation is needed between what is metadata and what is data that forms the body of the document. This affects ease of authoring and processing of the document because the context of the data is implied. The metadata needed for an element needs to structured in such a way that attributes are difficult to use.

Solution

Create head and body elements. The element that contains the head and body elements can be referred to as the skeleton element. The metadata for the document goes into the head element, and the data for the document itself goes into the body element. The XML takes the following form:
        

<Skeleton>
<Head>
... meta information ...
</Head>
<Body>
... body of document ...
</Body>
</Skeletion>

        
      

Examples

        

<Document>
<Head>
<Author>John Doe</Author>
<Author>Frank Black</Author>
<CreationDate>June 16, 1999</CreationDate>
</Head>
<Body>
This is a document.
</Body>
</Document>

        
      
In this case, the skeleton element is the document root, and the metadata is structured information about the authors of the document and the creation date of the document. The Head-Body pattern is often used at the document level, but it can also be used at levels deeper within a document. For example the pattern could be used inside of a Table element like this:
        

<Document>
<Table>
<TableHead>
<Title>
A <Italic>Sample<Italic> Table
</Title>
</TableHead>
<TableBody>
<Row>Row 1</Row>
<Row>Row 2</Row>
</TableBody>
</Table>
</Document>

        
      
In this case the skeleton element is a table, which needs structure for its Title data.

Discussion

Two new elements are introduced which distinguish the metadata from the body of the document. This gives processing software context to distinguish these two types of data.

Because this introduced two additional elements, the resulting documents are larger than they would be without the application of this pattern

The resulting documents are often easier to understand because of the clear separation of metadata and the document body itself. The metadata is in the Head element and the document itself goes in the Body element. Authors and processing software can clearly distinguish the context of the data they are using.

Documents are also often easier to process because they allow metadata to be structured, unlike if attributes were use for the metadata of the document.

For an interesting alternative, see Don Park's "Neck" pattern (http://www.docuverse.com/blog/donpark/EntryViewPage.aspx?guid=831)

Related Patterns

The Head-Body Pattern consists of two new Container Elements added to the structure of the document, one for the Head element, and one for the Body. This is a specialization of the Separate Metadata and Data.

Known Uses

HEAD and BODY elements in XHTML.

SOAP (Simple Object Access Protocol) (http://www.w3.org/TR/SOAP/) uses Header and Body Elements inside an Envelope element.

References

Rick Jelliffe discusses this in a chapter entitled "The Document Shell" in: The XML & SGML Cookbook: Recipes for Structured Information