Metadata First
Printable Version


Metadata should appear in a document before the data which it is about.


Many processors (for example SAX based parsers) are stream based. That is, the document is processed as it is read in, the whole document is never held in memory at the same time. If a piece of metadata appears after the data it refers to, the application software will need to store the data, then read the metadata in order to know what to do with the data.


Anywhere in the document that metadata appears.


The ease and speed of processing a document can be effected by the order in which the structures of the document appear.


Always make sure that metadata appears in a document before the data it refers to. This can be done whether the metadata is attribute data or element data.

For example, with the following code,


This is a new section<Font size="3"/>

If the processing software were trying to send this information to a printer, it would need to save the text of the heading, read in the font size, send the font size command to the printer, and then send the text to the printer. If the font element appeared before the text, there would be no need to save the text.


This example shows a table element with the height and width elements appearing before the actual data of the table. This allows the processing software to start rendering the table as the data is read in. If the height and width of the table came after the table data, the processing software would need to read in and save all the data before starting to display it.

<height unit="pixels">100</height>
<width unit="pixels">100</width>



Placing the metadata before the data that it is about will often simplify processing software. This is also often a natural way for people to think about the data, making documents easier to read and author.

Related Patterns:

The ordering of the head and body element in the Head-Body pattern is an application of this pattern.

Known Uses:

In XHTML The head, which contains metadata, and body which contains the content are always in that order. The table elements contain size and spacing data in the attributes of the table element, which places it before the data, and the caption and column width and spacing data appears before the table data itself.

Visit our sponsors: (Interested in advertising on XMLPatterns.com?)