TEI/XML Structure Documentation

Introduction

This editor is designed to work with TEI (Text Encoding Initiative) XML files that follow a specific structure. The files should contain three main sections: a TEI header with metadata, a facsimile section defining image zones, and a text section containing the transcribed content.

Expected TEI Structure

Important: The sections must appear in this order: teiHeader → text → facsimile

1. XML Declaration & Schema References

The XML declaration and schema references ensure proper validation and compatibility with TEI standards.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" 
            type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" 
            type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">

2. TEI Header

The TEI header contains metadata about the document, including title, responsibility statements for transcription and encoding, publication information, and source description.

<teiHeader>
  <fileDesc>
    <titleStmt>
      <title>Title</title>
      <respStmt>
        <resp>Automated Transcription</resp>
        <name ref="https://github.com/ndl-lab/ndlkotenocr-lite">
          NDL古典籍OCR-Liteアプリケーション
        </name>
      </respStmt>
      <respStmt>
        <resp>Conversion to TEI encoding</resp>
        <name>Editor Name</name>
      </respStmt>
    </titleStmt>
    <publicationStmt>
      <p>Publication Information</p>
    </publicationStmt>
    <sourceDesc>
      <p>Information about the source</p>
    </sourceDesc>
  </fileDesc>
</teiHeader>

3. Text Body

The text section contains the actual transcribed content. All content is wrapped in a single p element with pb for page breaks and lb for line breaks.

<text>
  <body>
    <p>
      <pb n="1"/>
      <lb corresp="#L0000_001" n="1" type="line"/>First line of text
      <lb corresp="" n="2" type="line"/>
      <lb corresp="#L0000_002" n="3" type="line"/>Third line with text
      <lb corresp="#L0000_003" n="4" type="annotation"/>Annotation text
    </p>
  </body>
</text>

Note: Text content follows directly after lb elements. Empty lines are represented by lb elements without following text. The corresp attribute links to zone IDs in the facsimile section.

4. Facsimile Section

The facsimile section defines rectangular zones on the page image. Each zone has coordinates and can be linked to text elements.

<facsimile>
  <surface lrx="0" lry="0" ulx="0" uly="0" xml:id="page-0" n="1">
    <graphic url="https://dl.ndl.go.jp/api/iiif/2585164/R0000005/full/full/0/default.jpg" 
             width="8292px" height="4794px"/>
    <zone xml:id="L0000_001" ulx="4351" uly="889" lrx="4607" lry="3267"/>
    <zone xml:id="L0000_002" ulx="4148" uly="905" lrx="4408" lry="3241"/>
    <zone xml:id="L0000_003" ulx="3866" uly="914" lrx="4145" lry="3242"/>
  </surface>
</facsimile>

Note: The facsimile section must come AFTER the text section. Surface elements require lrx, lry, ulx, uly attributes even if set to 0.

Key Elements

<zone> Zone Element

Defines a rectangular area on the page image:

  • xml:id - Unique identifier for the zone
  • ulx, uly - Upper-left corner coordinates
  • lrx, lry - Lower-right corner coordinates
  • type - Zone type (e.g., line, title, marginalia)
  • subtype - Optional subtype for further classification

<pb> Page Break

Marks the beginning of a new page:

  • n - Page number
  • facs - IIIF image URL for the page

<lb> Line Break

Marks the beginning of a new line:

  • n - Line number
  • type - Line type (e.g., line, title, annotation)
  • subtype - Optional subtype
  • corresp - Reference to the corresponding zone (e.g., #zone_001)

Sample Files

Download these sample files to see the expected structure:

Tips for Creating Compatible TEI Files

  • Always include both facsimile and text sections for full functionality
  • Use the corresp attribute to link lines to zones for visual overlay
  • Zone coordinates should match the actual image dimensions
  • IIIF image URLs in pb elements enable the image viewer
TEI/OCR Editor