2012-08-28

EPUB 2.0.1 is defined by four specs: OPS, NCX, OPF, and OCF. (NCX is a subset of a larger spec from Digital Talking Book that was incorporated into OPS.) These specs have been extended or replaced by EPUB 3.0.

Open Publication Structure (OPS)

OPS defines an EPUB document as a collection of XHTML pages and associated image and audio resources. EPUB 3.0 replaced XHTML with HTML5.

In EPUB 2.0.1, navigation through the document used DTBook's NCX design. The NCX element had a somewhat annoying structure that paralleled (X)HTML but required preprocessing for rendering by an HTML engine. NCX was made obsolete in the EPUB 3.0 specification.

EPUB 3.0 embeds navigation links into an HTML5 content page. The page can be rendered directly by a WebKit view without any special handling. Additional structure can be made available using the epub:type attribute, but it is not absolutely necessary for the reader software to support that. The content author should provide a reasonable navigation page.

Open Packaging Format (OPF)

OPF defines the structure of the Package File. The Package File contains a section that identifies all of the content pages and resources of the document. It also contains a section that defines the default linear reading order of the document.

An EPUB document consists of a top level folder and optional subfolders. The author can place content files within the hierarchy as desired. The top level folder must contain a file with an OPF extension which describes the rest of the files in the document. Example:

	PackageFile.opf
	cover.html
	chapters/
	      chapter01.html
	      chapter02.html
	      ... other OPS files for the remaining chapters ...

Within the .OPF file, metadata and guide sections may be ignored for a simple reader. The key sections are the manifest and the spine.

	<?xml version="1.0"?>
	<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
		<metadata> ... </metadata>
		<manifest> ... </manifest>
		<spine> ... </spine>
		<guide> ... </guide>
	</package>

The manifest associates an id and a media type to each (X)HTML file or resource used in the document. Example:

	<manifest>
		<item id="intro" href="introduction.html" media-type="application/xhtml+xml" />
		<item id="c1" href="chapter-1.html" media-type="application/xhtml+xml" />
		<item id="c2" href="chapter-2.html" media-type="application/xhtml+xml" />
		<item id="toc" href="contents.xml" media-type="application/xhtml+xml" />
		<item id="oview" href="arch.png" media-type="image/png" />
	</manifest>

In EPUB 3.0, "All Publication Resources must declare any applicable descriptive metadata properties as defined in Manifest item Properties via the item element properties attribute. Exactly one item must be declared as the EPUB Navigation Document using the nav property." Also, the navigation document may or may not be included in the spine list. In an EPUB 3.0 document, then, the reader must look for a NAV document in the manifest. Example:

	<manifest>
		...
		<item id="nav" href="nav.xhtml" properties="nav" media-type="application/xhtml+xml" />
		...
	</manifest>

The spine element defines a preferred reading order for the document's contents. Each component is referenced by the id defined for it in the manifest. Additional "out of band" components may be included in the spine by specifying the linear="no" attribute:

	<spine toc="ncx">
	     <itemref idref="intro" />
	     <itemref idref="c1" />
	     <itemref idref="c1-answerkey" linear="no" />
	     <itemref idref="c2" />
	     <itemref idref="c2-answerkey" linear="no" />
	     <itemref idref="c3" />
	     <itemref idref="c3-answerkey" linear="no" />
	     <itemref idref="note" linear="no" />
	</spine>

In EPUB 2.0.1, the spine has a mandatory attribute toc which contains the ID of the manifest element which references the NCX table of contents.

Navigation Center eXtended (NCX)

This is the example NCX from OPF 2.0.1 Section 2.4:

<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
    <head>
        <meta content="org-example-5059463624137734586" name="dtb:uid"/>
    </head>
    
    <docTitle>
        <text>Selections from "Great Pictures, As Seen and Described by Famous Writers"</text>
    </docTitle>
    
    <docAuthor>
        <text>Esther Singleton</text>
    </docAuthor>
    
    <navMap>
        <navPoint class="h1" id="ch1">
            <navLabel><text>Chapter 1</text></navLabel>
            <content src="content.html#ch_1"/>
            <navPoint class="h2" id="ch_1_1">
                <navLabel><text>Chapter 1.1</text></navLabel>
                <content src="content.html#ch_1_1"/>
            </navPoint>
        </navPoint>
        <navPoint class="h1" id="ncx-2">
            <navLabel><text>Chapter 2</text></navLabel>
            <content src="content.html#ch_2"/>            
        </navPoint>
    </navMap>
    
    <pageList>
        <pageTarget id="p1" type="normal" value="1">
            <navLabel><text>1</text></navLabel>
            <content src="content.html#p1"/>
        </pageTarget>
        <pageTarget id="p2" type="normal" value="2">
            <navLabel><text>2</text></navLabel>
            <content src="content.html#p2"/>
        </pageTarget>        
    </pageList>
    
    <navList>
        <navLabel><text>List of Illustrations</text></navLabel>
        <navTarget id="ill-1">
            <navLabel><text>Portratit of Georg Gisze (Holbein)</text></navLabel>
            <content src="content.html#ill1"/>
        </navTarget>
        <navTarget id="ill-2">
            <navLabel><text>The adoration of the lamb (Van Eyck)</text></navLabel>
            <content src="content.html#ill2"/>
        </navTarget>
    </navList>
</ncx>

The navMap element is required and it contains a hierarchical table of contents. Notice how the navPoint elements may nest to create new levels. The pageList is optional. There may be zero or more navList elements for content such as a List of Illustrations, List of Tables, Footnotes, etc. The pageList and navList elements do NOT allow nesting.

The text elements within navLabel elements seem redundant here, but in the original Digital Talking Book spec, text elements had parallel audio elements which pointed to sound files that could be read to the user.

Open Container Format (OCF)

OCF defines a physical container (a ZIP file) that can contain one or more views of an OPF logical document. OCF defines additional components that appear only in the ZIP file container. Example:

	mimetype
	META-INF/
	   container.xml
	   [manifest.xml]
	   [metadata.xml]
	   [signatures.xml]
	   [encryption.xml]
	   [rights.xml]
	OEBPS/
	   Great Expectations.opf
	   cover.html
	   chapters/
	      chapter01.html
	      chapter02.html
	      ... other OPS files for the remaining chapters ...

The mimetype file must be the first entry in the ZIP file. (Some existing reading programs may check for binary contents at a specific offset within the container file as a shortcut integrity check without performing a full ZIP search.) The mimetype file must consist of the ASCII characters:

application/epub+zip

The container.xml file defines one or more root files describing the document. There could be alternate roots for viewing and printing, for example. The first root file with attribute media-type="application/oebps-package+xml" is the default document for reading. Example:

	<?xml version="1.0"?>
	<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
	  <rootfiles>
	    <rootfile full-path="OEBPS/Great Expectations.opf" media-type="application/oebps-package+xml" />
	  </rootfiles>
	</container>

Ignore the META-INF/manifest.xml file if it exists. It is a legacy element of the ODF 1.0 spec. The manifest items within the .OPF file override it completely.

References