Answers.Body: <p>I'll post an answer which seems to be working for me.</p>
  
  <p>I found relevant documentation here: <a href="http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-package-documents" rel="nofollow noreferrer">http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-package-documents</a></p>
  
  <p>Using Ruby and Nokogiri, I decompressed the ePub file, read the package document as HTML, then used an XPath statement:</p>
  
  <pre><code>unzipped_file   = Zip::File.open(epub_file)
  package_file    = unzipped_file.glob("*/package.opf").first
  package_as_html = Nokogiri::HTML(package_file.get_input_stream.read)
  package         = package_as_html.at_xpath("html/body/package")
  
  nav_file_name   = package.
                      at_xpath("manifest/item[@properties='nav']").
                      attribute("href").
                      text
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-23T08:40:29.463Z
Answers.LastActivityDate: 2018-01-23T08:40:29.463Z
Answers.UserDisplayName: David Aldridge
Body: <p>I've been looking at a few different ePub3s (programatically, not through ePub-specific software), and notive that the navigation document containing the TOC doesn't seem to be constantly named.</p>
  
  <p>Is there a way of finding it, other than through reading each file for the relevant HTML?</p>
  
  <p>Thanks</p>
  
  <p>Edit: Digging around further, perhaps the package.opf is the answer: <code>&lt;item id="nav_1" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"&gt;&lt;/item&gt;</code>?</p>
  
Tags: <epub><table-of-contents>
Title: ePub 3: Finding the Navigation document
UserDisplayName: David Aldridge
ThreadText: # ePub 3: Finding the Navigation document
  
  (Asked by: username_0 on 2018-01-22)
  
  I've been looking at a few different ePub3s (programatically, not through ePub-specific software), and notive that the navigation document containing the TOC doesn't seem to be constantly named.
  
  Is there a way of finding it, other than through reading each file for the relevant HTML?
  
  Thanks
  
  Edit: Digging around further, perhaps the package.opf is the answer: ?
  
  **Tags:** epub, table-of-contents
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-01-23. Score: 1
  
  I'll post an answer which seems to be working for me.
  I found relevant documentation here: http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-package-documents
  Using Ruby and Nokogiri, I decompressed the ePub file, read the package document as HTML, then used an XPath statement:
  unzipped_file   = Zip::File.open(epub_file)
  package_file    = unzipped_file.glob("*/package.opf").first
  package_as_html = Nokogiri::HTML(package_file.get_input_stream.read)
  package         = package_as_html.at_xpath("html/body/package")
  
  nav_file_name   = package.
                      at_xpath("manifest/item[@properties='nav']").
                      attribute("href").
                      text
  
  
  ---
  
  