You are here

TEI Code & Exercises

XML Markup

Code Example 0: XML markup

<person>John Adams</person>

<person type="president">John Adams</person>

(The above marks this as a specific classification of "John Adams" with the use of an XML "attribute").

But we can get more fine-grained than this by encoding the forename and surname separately.

<person type="president"><forename>John</forename> <surname>Adams</surname><person>


Code Example 1:



Code Example 2:

<person type="olympian">


Code Example 3:

    <title>Tragic Events in South Africa</title>
    <date>February 19, 2013</date>
          <sentence>It was a dark and stormy night.</sentence>
          <sentence>Oscar Pistorius thought an intruder was in the house.</sentence>
          <sentence>He pulled out his 9mm pistol, moved toward the bathroom and fired into the door.</sentence>

TEI Encoding

Code Example 4:


Note: There are two errors in this code, a tag mismatch and a missing slash. Can you find them?



1. Copy the following line into computer memory:

<div><p>My name is <persName><forename>___</forename> <surname>___</surname></persName></p></div>

2. Go to TBE validation service - checks your TEI encoding for errors

3. Replace "___" with your first name and last name

4. Add <forename>[your middle initial]</forename>

5. Keep the "TBE validation service" tab open and go back to the Exercises page.

Encoding a Poem with TEI

Code Example 5: Basic Structure of a TEI Document
        <!--- Insert bibliographic information about the text. -->
        <!-- Insert the poem itself here. -->



1. Go back to the open "TBE validation service." (TBE validation service)

2. Click "Copy to Input."

3. Type in something for the title header <title> and <publisher>

<title>My first TEI project</title>
<publisher>Hamilton College</publisher>

Source of poem:

Code Example 6: TEI markup of teiHeader of "Ghazal"

<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="" xml:lang="en">
                <title>Ghazal: a machine-readable transcription</title>
                    <name>Agha Shahid Ali</name>
                    <name>Peter J. MacDonald</name>
                <publisher>Hamilton College</publisher>
                <pubPlace>Clinton, New York</pubPlace>
                <date when="2013"/>
                <p>"Ghazal," by Agha Shahid Ali, originally published in "Rooms Are Never Finished," Copyright ©
                    2002 by Agha Shahid Ali</p>


Code Example 7. Marking up the Text Layout of a Poem (stanzas, line, fonts, underlining, indenting):

                  <l>I'll do what I must if I'm bold in real time.</l>
                  <l>A refugee, I'll be paroled in real time.</l>
                  <l>Cool evidence clawed off like shirts of hell-fire?</l>
                  <l>A former existence untold in real time ... </l>
                  <l>The one you would choose: Were you led then by him?</l>
                  <l>What longing, O <hi rend="italic">Yaar</hi>, is controlled in real time?</l>

<lg> = line group
<l> = line
<lb = line break
<hi rend="italic"> = render the text with italic font


Code Example 8: Marking up the Poetic Form of a Poem (rhyme, meter):

        <lg type="poem">
            <lg type="couplet" n="1">
                <l n="1">I'll do what I must if I'm <rhyme label="a">bold</rhyme> <rhyme label="b" xml:id="A">in real time</rhyme>.</l>
                <l n="2">A refugee, I'll be <rhyme label="a">paroled</rhyme> <rhyme label="b" corresp="#A">in real time</rhyme>.</l>
            <lg type="couplet" n="2">
                <l n="3">Cool evidence clawed off like shirts of hell-fire?</l>
                <l n="4">A former existence untold <rhyme label="a" corresp="#A">in real time</rhyme> ... </l>
            <lg type="couplet" n="3">
                <l n="5">The one you would choose: Were you led then by him?</l>
                <l n="6">What longing, O <hi rend="italic">Yaar</hi>, is controlled <rhyme label="a" corresp="#A">in real time</rhyme>?</l>

<x @type=""> = type of x
<x @n=""> = unique number assigned to this x
<rhyme> = rhyme scheme: a, b, etc.
<x @xml:id="n"> = unique number representing this content
<x @corresp="#Y"> = content corresponds to another item had @xml:id:Y


Code Example 9: Mark up the Semantics.

      <interpGrp resp="PMacD" type="imagery">
          <interp xml:id="uncertainty">uncertainty unknown hidden</interp>
          <interp xml:id="assertivenes">assertiveness action</interp>
          <interp xml:id="hope">desire hope longing</interp>
          <interp xml:id="salvation">salvation safety renewal</interp>
          <interp xml:id="temporalDislocation">dislocation, distancing, tempral
          <interp xml:id="spatialDislocation">home, geographic terminology</interp>
          <interp xml:id="socialDislocation">social dislocation, stranger, strangeness,
          <interp xml:id="nostalgia">nostalgia, memory, remembering</interp>
          <interp xml:id="victimization">victimization</interp>
          <interp xml:id="adversity">adversity, danger, opposition, challenges</interp>

          <lg type="ghazal">
              <lg type="couplet" n="1">
                  <l n="1">
                      <seg ana="#assertiveness">I'll do what I must</seg>
                      <seg ana="#uncertainty">if I'm bold</seg>
                      <seg ana="#temporalDislocation">in real time</seg>.</l>
                  <l n="2">A <seg ana="#socialDislocation">refugee</seg>,
                      <seg ana="#salvation">I'll be paroled</seg>
                      <seg ana="#dislocation">in real time</seg>.</l>
              <lg type="couplet" n="2">
                  <l n="3"><seg ana="#adversity">Cool evidence clawed off like shirts of hell-fire?</seg></l>
                  <l n="4">A <seg ana="#temporalDislocation">former existence</seg>
                      <seg ana="#uncertainty">untold</seg>
                      <seg ana="#temporalDislocation">in real time</seg> ... </l>
              <lg type="couplet" n="3">
                  <l n="5">The one you <seg ana="#modality">would</seg>
                      <seg ana="#assertiveness">choose</seg>:
                      <seg ana="#uncertainty">Were you led then by him?</seg></l>
                  <l n="6">What <seg ana="#hope">longing</seg>, O <foreign><hi rend="italic">Yaar</hi></foreign>, is controlled
                      <seg ana="#temporalDislocation">in real time</seg>?</l>



1. Copy the following entire poem into computer memory:

2. Go to the TEImatron.

3. Paste in the poem.

4. Click "Submit."


TEI gives us a standard vocabulary to make explicit the form and meaning of a poem so computers can process it.



Learning TEI Encoding

Processing Engines for TEI files

Hamilton College Library TEI Projects


TEI Projects with Dynamic Output

TEI Project under development

- Top -

(Reviewed: February 27, 2013)