开发者

iPhone - reading .epub files

开发者 https://www.devze.com 2023-01-27 14:12 出处:网络
I am engaged in preparing an application regarding re开发者_JAVA百科ading the .epub files in iPhone. Where can I get the reference for sample applications for unzipping and parsing the files? Can anyo

I am engaged in preparing an application regarding re开发者_JAVA百科ading the .epub files in iPhone. Where can I get the reference for sample applications for unzipping and parsing the files? Can anyone guide me with a best link? Thank you in advance.


An .epub file is just a .zip file. It contains a few directory files in XML format and the actual book content is usually XHTML. You can use Objective-Zip to unzip the .epub file and then use NSXMLParser to parse the XML files.

More info: Epub Format Construction Guide


On top of Ole's answer (that's a pretty good how-to guide), it's definitely worth reading the specification for the Open Container Format (OCF) - sorry it's a word file. It's the formal specification for the for zip structure used.

In brief you parse the file by

  1. Checking it's plausibly valid by looking for the text 'mimetype' starting at byte 30 and the text 'application/epub+zip' starting at byte 38.
  2. Extracting the file META-INF/container.xml from the zip
  3. Parsing that file and extracting the value of the full-path attribute of the first rootfile element in it.
  4. Load the referenced file (the full-path attribute is a URL relative to the root of zip file)
  5. Parse that file. It contains all the metadata required to reference all the other content (mostly XHTML/CSS/images). Particularly you want to read the contents of the spine element which will list all content files in reading order.

If you want to do it right, you should probably also handle DTBook content as well.

If you want to do this right, you need to read and understand the Open Packaging Format (OPF) and Open Publication Structure (OPS) specifications as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消