Next: MEI Basics Quiz
General MEI Document Structure
MEI provides an XML-based schema that describes music notation, using both XML elements and attributes. An element, often referred to as XML tag, is notated in angle brackets:<elementName></elementName>
The name of an element is case sensitive, and every element consists of an opening and closing tag. The closing tag contains a solidus character (forward slash), which precedes the element name. An element may contain one or more other elements, XML comments, or text. Content is nested within the opening and closing tag of the element.
Elements must be nested properly, with the element opened last being closed first, in order to comply with the rules of XML.
An element may be described further by adding attributes to it. These attributes are attached to the element's name in the opening tag, separated by a space character.
Attributes can be listed in any order within a particular element. Whereas elements may be specified further by attributes, there is no mechanism for providing additional information about attributes. Therefore, attributes are less versatile than elements. In running text, attributes are often referred to by attaching a preceding @ character.
Elements lacking content, i.e., containing nothing, not even white space characters, such as spaces or tabs, between their opening and closing tags, may be written as empty elements:
<sb></sb> or <sb/>
In the last case, the solidus character at the end of the element's name indicates that the opening tag is also functioning as the closing tag. This mechanism is independent of the use of attributes.
An XML document following these general rules of XML is "well-formed“. In addition to being well-formed, an XML document may be "valid" with regard to a schema, such as MEI, meaning that it also reflects the structure defined by that particular schema. The following instructions assume well-formed and valid MEI documents.
Every MEI document consists of two main parts:
- the MEI Header and
- the MEI music.
1 The MEI Header
In addition to providing a means of electronically transcribing or encoding the musical content of a given piece of music notation, MEI also enables the capture of information about this encoded material (title, source, related works, data about creation, etc.), using the MEI Header, represented by the <meiHead> element. While this part of the schema is modeled on the respective sections of the Text Encoding Initiative (TEI), the Encoded Archival Description (EAD), or other metadata encoding and transmission standard formats, it is specifically adjusted to address the needs of musicologists, music librarians, and others in the field.
Every MEI file requires a minimal header. The header in the example below provides information about the title of the digital resource and details of its publication status. Of course, other details may be specified using a variety of optional elements. The tutorials included in MEI 1st illustrate the wide range of use cases showing the functionality of the MEI Header.
2.1 Basic Structure of an MEI Document
The example below shows a typical, simple MEI document, using the <mei> document element , which consists of some metadata, represented by the <meiHead>, and the <music> itself. The <music> element is the container for the complete musical text and makes some important constituents available. The following example shows the mei document element with the appropriate namespaces (briefly, the namespace is a definition required for all XML documents), the required <meiHead>, and an empty <music> element.
<title>title of the encoded example</title>
While the <music> element is required in this case, it may be empty. The <music> element is simply a placeholder for content that is not yet provided.
2.2 Body and Group
The structure below illustrates a musical text with an <music> element and the sub-element <body>. The <body> element must contain at least one segment, known as a "musical division" (<mdiv>). A simple score serves as an example here to demonstrate the general structure of contents within the <score> element:
Beginning of Robert Schumann's song Der Abendstern
<scoreDef meter.count="2" meter.unit="4" key.sig="3s">
<staffDef n="1" label="Singstimme." lines="5" clef.shape="G" clef.line="2"/>
<staffGrp symbol="brace" label="Pianoforte.">
<staffDef n="2" lines="5" clef.shape="G" clef.line="2"/>
<staffDef n="3" lines="5" clef.shape="F" clef.line="4"/>
The <score> element contains a score definition (<scoreDef> element), which acts as a container for score meta-information (i.e., information related to the whole score, such as meter). The score definition (<scoreDef>) may in turn include one or more staff definitions (<staffDef>, which can be grouped by one or more staff groups (<staffGrp>). As shown in the example, the <staffGrp> element can be used to specify the symbol used to group a set of staves. It is also possible to encode staff groups within other staff groups. Specific information about individual staves of a score, such as clefs or key signatures, is encoded within staff definitions (<staffDef>). Names of single instrument voices may be encoded in staff definitions or in staff groups.
Multiple musical division (<mdiv>) may be encoded within a file. In describing the separate movements of a symphony, for example, separate <mdiv> elements are used to demarcate the different segments. <mdiv> elements may also be nested within another when the structure requires it, as in the following sample of an opera:
The <mdiv> element is a critically important part of the structure of an MEI file. The content of the divisions is also significant, as that decision will enable one of two possible views: <score> and <parts>. Each of the elements may contain elements and attributes for describing features such as clefs, key signature, meter, etc.
If you would like to encode a single violin part, the main structure could look like this:
<staffDef n="1" label="Violin" lines="5" meter.count="3" meter.unit="4" clef.shape="G" clef.line="2" key.sig="1s"/>
When encoding performer's parts, for example those of a string quartet, a separate <part> element must be created for each of the instrument voices. Each of these may include its own staff definition (<staffDef>).
In contrast to the <body> element, the <group> element enables the encoding of a group of essentially-separate musical texts. If, for example, you are encoding a collection of songs, you can nest one or more <music> elements, along with their respective <body>, <mdiv>, <score>, or other elements, within <group>, as seen in the example below.
As you can see, while the MEI basic framework is very simple, it can be used to model complex situations.
2.3 Front and Back
The elements <front> and <back> are children of the <music> element and are located on the same hierarchical level as the elements <body> and <group>. They are used to describe extensive introductory texts, for instance, those in critical editions and collected works. Both the <front> element and the <back> element require a mandatory division (<div>) child element, which itself requires a paragraph (<p>) child element containing the actual text you are encoding. An example of this hierarchical structure is illustrated below:
<p><!-- introductory text here --></p>
<!-- music notation -->
<p><!-- "back matter" here --></p>
The <section> element is a child element of the <score> or <part> element and may be used to divide a score or parts into further linear segments, so called sections. Within the <section> element, several methods of organization are possible, depending upon the notational style of the source material and the encoder's needs. A section can be described as the container for the actual musical data of an individual segment in a musical work.
<!-- musical data for this segment of the musical work -->
This section has presented the most fundamental MEI elements and suggestions for their proper use in encoding both text and music within the MEI document.
More examples and detailed descriptions of several elements, including their attribute classes, can be found in the Guidelines .