Head-Body and Neck

Head-Body is a well known design pattern for markup languages such as XML, HTML, and RSS.  Most common example is HTML which has <head> and <body> elements under <html> root element to separate metadata from content.  Another example is SOAP where Head-Body pattern is used to separate information on the envelope from the payload inside the envelope.

While the Head-Body pattern is well-known, it can be confusing in practice as Mark Pilgrim and Sam Ruby's recent posts indicate.  The pattern also adds verbosity and complexity to document structure and language bindings because it adds an extra layer of elements between the container elements and contained elements (i.e. dog.body.tail instead of dog.tail).

I came up with an alternative to the Head-Body pattern while waiting for Vikingsholm tour to start at Emerald Bay: the Neck pattern.  The basic idea is to use a divider (<neck> element) instead of two boxes (<head> and <body>).

Here is a silly example of Head-Body:

<animal>
    <head>
        <eyes>2</eyes>
        <nose>1</nose>
        <mouth>1</mouth>
    </head>
    <body>
        <legs>4</legs>
        <tail>1</legs>
    </body>
</animal>
And here is Neck version of the same:
<animal>
    <eyes>2</eyes>
    <nose>1</nose>
    <mouth>1</mouth>
    <neck/>
    <legs>4</legs>
    <tail>1</legs>
</animal>
FYI, the Neck pattern is an instance of the Road Sign pattern.