General MEI Document Structure

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.

<elementName>
    <subElement>Text</subElement>
    <subElement></subElement>
</elementName>

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 Music

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.

<mei xmlns="http://www.music-encoding.org/ns/mei">
    <meiHead>
        <fileDesc>
            <titleStmt>
                <title>title of the encoded example</title>
             </titleStmt>
             <pubStmt/>
        </fileDesc>
    </meiHead>
    <music/>
</mei>

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:

image
Beginning of Robert Schumann's song Der Abendstern

Encoding:
<music>
    <body>
        <mdiv>
            <score>
                <scoreDef meter.count="2" meter.unit="4" key.sig="3s">
                    <staffGrp symbol="line">
                        <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"/>
                        </staffGrp>
                    </staffGrp>
                </scoreDef>
            </score>
        </mdiv>
    </body>
</music>

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:

<music n="opera">
    <body>
        <mdiv n="act_1">
            <mdiv n="scene_1">
                <score/>
            </mdiv>
        </mdiv>
        <mdiv n="act_2">
            <score/>
        </mdiv>
        <mdiv n="act_3">
            <score/>
        </mdiv>
    </body>
</music>

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:

<music>
    <body>
        <mdiv>
            <parts>
                <part>
                    <staffDef n="1" label="Violin" lines="5" meter.count="3" meter.unit="4" clef.shape="G" clef.line="2" key.sig="1s"/>
                </part>
            </parts>
        </mdiv>
    </body>
</music>

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.

<music>
    <group>
        <music n="song_1">
            <body>
                <mdiv/>
            </body>
        </music>
        <music n="song_2">
            <body>
                <mdiv/>
            </body>
        </music>
    </group>
</music>

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:

<music>
    <front>
        <div>
            <p><!-- introductory text here --></p>
        </div>
    </front>
    <body>
        <!-- music notation -->
    </body>
    <back>
        <div>
            <p><!-- "back matter" here --></p>
        </div>
    </back>
</music>

2.4 Section

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.

<music>
    <body>
        <mdiv>
            <score>
                <section>
                    <!-- musical data for this segment of the musical work -->
                </section>
            </score>
        </mdiv>
    </body>
</music>

2.5 Summary

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 .