Skip to content

Instantly share code, notes, and snippets.

@elmimmo
Last active March 8, 2016 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmimmo/d7b8dbebc4e972734e9a to your computer and use it in GitHub Desktop.
Save elmimmo/d7b8dbebc4e972734e9a to your computer and use it in GitHub Desktop.
The NCX DOCTYPE is not required in EPUB 2, and you are actually better off without it. See why.
<?xml version="1.0" encoding="UTF-8"?>
<ncx version="2005-1" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>
<meta name="dtb:uid" content="urn:uuid:e04c4d19-57af-4495-a8c8-882695b7c8dc" />
</head>
<docTitle>
<text/>
</docTitle>
<navMap>
<navPoint id="title_page">
<navLabel>
<text>My EPUB test</text>
</navLabel>
<content src="title_page.xhtml" />
</navPoint>
<navPoint id="ch001">
<navLabel>
<text>First chapter</text>
</navLabel>
<content src="ch001.xhtml" />
</navPoint>
<navPoint id="ch002">
<navLabel>
<text>Second chapter</text>
</navLabel>
<content src="ch002.xhtml" />
</navPoint>
</navMap>
</ncx>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx version="2005-1" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>
<meta name="dtb:uid" content="urn:uuid:e04c4d19-57af-4495-a8c8-882695b7c8dc" />
<meta name="dtb:depth" content="1" />
<meta name="dtb:totalPageCount" content="0" />
<meta name="dtb:maxPageNumber" content="0" />
</head>
<docTitle>
<text>My EPUB test</text>
</docTitle>
<navMap>
<navPoint id="title_page" playOrder="1">
<navLabel>
<text>My EPUB test</text>
</navLabel>
<content src="title_page.xhtml" />
</navPoint>
<navPoint id="ch001" playOrder="2">
<navLabel>
<text>First chapter</text>
</navLabel>
<content src="ch001.xhtml" />
</navPoint>
<navPoint id="ch002" playOrder="3">
<navLabel>
<text>Second chapter</text>
</navLabel>
<content src="ch002.xhtml" />
</navPoint>
</navMap>
</ncx>
@elmimmo
Copy link
Author

elmimmo commented Aug 20, 2014

before-toc.ncx is how many EPUB creation software generate the NCX document, with its correspoding DOCTYPE declaration linking to the DTD governing its specification:

<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" 
     "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">

This document validates as a proper NCX document. One of the requirements of the NCX specification is that each navPoint element has a playOrder attribute, its value being a whole number, starting with 1 for the first navPoint element and incrementing by 1 for each consecutive one, with no gaps.

<navPoint id="navPoint-1" playOrder="1">

That sucks big time if you ever have to customize the TOC and therefore add or delete navPoint elements manually (yeah, you shouldn’t have to in the first place with an ideal workflow, but not everybody can tweak their tools, choose them or even build their own).

The EPUB 2 specification, though, does actually state that one can omit the NCX DOCTYPE declaration, in which case some of the requirements of the NCX spec that are irrelevant for EPUB are lifted. Specifically, without a DOCTYPE, one can omit the dreadful playOrder attribute altogether, along with those pointless meta elements (except for the dtb:uid one). And thus, the NCX document becomes after-toc.ncx.

As a matter of fact, epubcheck 3.0.1 does not report as invalid even an EPUB 2 whose NCX has the DOCTYPE declared and whose all (but not just some) navPoint elements lacks the playOrder attribute, even though, if being strict, that would indeed be an invalid EPUB. But no ereader uses that attribute for anything (or none should, at least) so either voluntarily or not, epubcheck is choosing being practical over being strict.

PS: Omitting the NCX DOCTYPE is optional in EPUB 2, but actually required in EPUB 3.

@libraryhead
Copy link

I've been leaving off play order for months, never a validation error, never a problem with retailers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment