简体   繁体   English

如何使用C#解析ncx文件

[英]How to parse an ncx file using c#

I am trying to create a windows phone app for reading e-pubs. 我正在尝试创建Windows Phone应用来阅读电子酒吧。 I extracted the content and now I want to read the ncx file. 我提取了内容,现在我想读取ncx文件。 But when I try to use System.Xml.Serialization.XmlSerializer it is telling me unknown field in the second line itself. 但是,当我尝试使用System.Xml.Serialization.XmlSerializer时,它告诉我第二行本身中的未知字段。 Please help 请帮忙

Here is how the basic approach to read an epub file 这是读取epub文件的基本方法

  • Treat the EPUB file as a ZIP archive and read it using the Windows built-in ZIP archive reader, ZipArchive 将EPUB文件视为ZIP存档,并使用Windows内置的ZIP存档阅读器ZipArchive读取它
  • In the archive, find the file META-INF/container.xml and look in it 在档案中,找到文件META-INF / container.xml并查找
    to find the full-path attribute of the root-file element. 查找根文件元素的全路径属性。 That gives you the path to the OPF file (probably something like 这为您提供了OPF文件的路径(可能类似于
  • OPS/content.opf) The 'manifest' element of the OPF file will tell OPS / content.opf)OPF文件的“清单”元素将告诉您
    you the names of all the files that make up the book. 您组成本书的所有文件的名称。 The 'spine' “脊柱”
    element will tell you the order in which they appear in the book (and will include a reference, via the 'toc' attribute of the spine 元素会告诉您它们在书中出现的顺序(并通过书脊的'toc'属性包括参考)
    element, to a table-of-contents file that will usually be in NCX 元素,通常是NCX中的目录文件
    format) 格式)
  • Normally, the EPUB book will consist of series of XHTML files, each file containing one 'chapter' of the book. 通常,EPUB书将由一系列XHTML文件组成,每个文件都包含书的一个“章节”。 The basic procedure to display a book for reading would be: 显示要阅读的书的基本过程是:
    • figure out which chapter the user wants to look at 弄清楚用户要看哪一章
    • load the XHTML for that chapter into a WebView (or some other solution for rendering XHTML on screen) 将该章的XHTML加载到WebView中(或其他一些在屏幕上呈现XHTML的解决方案)

Problems you are likely to encounter: 您可能会遇到的问题:

  • Many EPUB books are created using ZIP-generators that, although compatible with the ZIP standard, are incompatible with the ZIP-reader APIs built into the OS. 许多EPUB图书都是使用ZIP生成器创建的,尽管它们与ZIP标准兼容,但与操作系统内置的ZIP阅读器API不兼容。 You will probably need to use a third party library like DotNetZip or SharpZipLib (but be careful of the licence conditions for the latter). 您可能需要使用第三方库,例如DotNetZip或SharpZipLib(但要注意后者的许可条件)。

  • You will need to do some work to display images in the WebView, especially if you try to cover all the image types that are part of the EPUB standard. 您将需要做一些工作才能在WebView中显示图像,尤其是当您尝试覆盖EPUB标准中的所有图像类型时。

  • It will be fiddly to find and apply all the CSS styles that the EPUB book defines. 找到并应用EPUB书中定义的所有CSS样式将是一件轻而易举的事情。

  • You will probably want to display a 'paged' view of the chapter, rather than displaying it as a long vertically scrollable column. 您可能需要显示章节的“分页”视图,而不是将其显示为垂直可滚动的长列。 That will involve some funky javascript work. 那将涉及一些时髦的JavaScript工作。

  • You may find that an individual EPUB chapter is too large for displaying in a WebView. 您可能会发现单个EPUB章节太大而无法在WebView中显示。 In the end, you may decide that all the limitations of WebView mean you will be better off writing your own custom XHTML-parsing rendering solution, and displaying using TextBlocks, or something more exotic (you can use C++ interop code and the D2D Font APIs) 最后,您可能会认为WebView的所有局限性意味着最好编写自己的自定义XHTML解析呈现解决方案,并使用TextBlocks或其他更奇特的方式进行显示(可以使用C ++互操作代码和D2D Font API )

To parse .epub file you may want to use a library : 要解析.epub文件,您可能需要使用一个库:

source on SO : 1 2 3 4 SO的来源: 1 2 3 4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM