阅读ePub格式 [英] Reading ePub format

查看:143
本文介绍了阅读ePub格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个iPhone应用程序来读取ePub文件。有没有可用于开发此框架的框架?我不知道如何阅读这种文件格式。我尝试使用NSXML Parser解析扩展名为.epub的示例文件,但是失败了。

I am trying to develop an iPhone application to read ePub files. Is there any framework available to develop this? I have no idea about how to read this file format. I tried to parse a sample file with .epub extension using NSXML Parser, but that fails.

推荐答案

EPUB格式汇集了一堆不同的规格/格式:

The EPUB format brings together a bunch of different specifications / formats:


  • 一个用来说明书的内容应该是什么样的(XHTML 1.1 + CSS的一个子集)

  • 一个用于定义清单,列出构成该内容的所有文件(OPF,即XML文件)

  • 一个定义如何打包所有内容(OEBPS:清单中所有内容的zip文件以及一些额外文件)

规格外观有点令人生畏但实际上一旦你掌握了基础知识(解压缩,解析XML),就不会特别困难或复杂了。

The specs look a bit daunting but actually once you've got the basics (unzipping, parsing XML) down it's not particularly difficult or complex.

你需要弄清楚如何下载EPUB,将其解压缩到某处,解析清单然后显示相关内容。

You'll need to work out how to download the EPUB, to unzip it somewhere, to parse the manifest and then to display the relevant content.

如果您刚刚开始,请注意以下几点:

Some pointers if you're just starting out:

  • parse xml
  • unzip

要显示内容,只需使用 UIWebView 目前。

To display content just use a UIWebView for now.

以下是您的代码的高级步骤:

Here's a high level step by step for your code:

1)用 UIWebView创建一个视图

2)下载EPUB文件

2) download the EPUB file

3)使用上面链接的zip库将其解压缩到应用程序文档文件夹中的子目录

3) unzip it to a subdirectory in your app's documents folder using the zip library, linked above

4)解析使用TBXML在 META-INF / container.xml (如果此文件不存在,EPUB无效)的XML文件,链接在上面

4) parse the XML file at META-INF/container.xml (if this file doesn't exist the EPUB is invalid) using TBXML, linked above

5)在这个XML中,找到第一个带有media-type application / oebps-package + xml 的rootfile。这是本书的OPF文件。

5) In this XML, find the first "rootfile" with media-type application/oebps-package+xml. This is the OPF file for the book.

6)解析OPF文件(也是XML)

6) parse the OPF file (also XML)

7 )现在你需要知道这本书的第一章是什么。

7) now you need to know what the first chapter of the book is.

a)< manifest> < item> c $ c>元素有一个id和一个href。将它们存储在 NSDictionary 中,其中键是id,对象是href。

a) each <item> in the <manifest> element has an id and an href. Store these in an NSDictionary where the key is the id and the object is the href.

b)看看< spine> 中的第一个< itemref> 。它有一个idref属性,对应于(a)中的一个id。在 NSDictionary 中查找该ID,您将获得一个href。

b) Look at the first <itemref> in the <spine>. It has an idref attribute which corresponds to one of the ids in (a). Look up that id in the NSDictionary and you'll get an href.

c)这是该文件第一章向用户展示。弄清楚完整路径是什么(提示:它是将zip文件解压缩到(3)中的位置加上(6)中OPF文件的基本目录)

c) this is the the file of the first chapter to show the user. Work out what the full path is (hint: it's wherever you unzipped the zip file to in (3) plus the base directory of the OPF file in (6))

8)使用 fileURLWithPath:创建 NSURL ,其中路径是(7c)的完整路径。使用您在(1)中创建的 UIWebView 加载此请求。

8) create an NSURL using fileURLWithPath:, where the path is the full path from (7c). Load this request using the UIWebView you created in (1).

您需要实现向前/向后按钮或滑动或其他东西,以便用户可以从一个章节移动到另一个章节。使用< spine> 计算下一个要显示的文件 - XML中的< itemrefs> 按照他们应该向读者显示的顺序。

You'll need to implement forward / backward buttons or swipes or something so that users can move from one chapter to another. Use the <spine> to work out which file to show next - the <itemrefs> in the XML are in the order they should appear to the reader.

这篇关于阅读ePub格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆