Permalink
Browse files

Spine parsing

  • Loading branch information...
1 parent 5040ebd commit 656cbfb3cd8adea3e7b0b77297bdceec5c600c41 @drotiro committed May 10, 2012
Showing with 22 additions and 4 deletions.
  1. +18 −2 src/Epub.cpp
  2. +4 −0 src/Epub.h
  3. +0 −2 src/Xml.cpp
View
@@ -10,6 +10,7 @@
#include "Xml.h"
using std::string;
+using std::vector;
Epub * Epub::createFromFile(const char *fileName) {
Epub * book = new Epub();
@@ -31,19 +32,34 @@ bool Epub::check() {
// read opf path from container
string container = zf->getFile("META-INF/container.xml");
Xml cx(container);
- std::vector<string> xr = cx.xpath("//rootfile/@full-path");
+ vector<string> xr = cx.xpath("//rootfile/@full-path");
if(xr.size() == 0 ) return false;
+ string opfpath = xr[0];
+ base = opfpath.substr(0, opfpath.find_last_of('/'));
// parse opf
Xml::nslist * ns = new Xml::nslist();
(*ns)["dc"] = "http://purl.org/dc/elements/1.1/";
- Xml opf(zf->getFile(xr[0]));
+ (*ns)["opf"] = "http://www.idpf.org/2007/opf";
+ Xml opf(zf->getFile(opfpath));
xr = opf.xpath("//dc:title", ns);
if(xr.size()) title = xr[0];
xr = opf.xpath("//dc:creator", ns);
if(xr.size()) author = xr[0];
xr = opf.xpath("//dc:publisher", ns);
if(xr.size()) publisher = xr[0];
+ // Items:
+ // get //itemref/@idref and read the item's href
+ xr = opf.xpath("//opf:itemref/@idref", ns);
+ string ix;
+ vector<string> nestx;
+ for(vector<string>::iterator it = xr.begin(); it != xr.end(); ++it) {
+ ix = "//opf:item[@id='";
+ ix.append(*it);
+ ix.append("']/@href");
+ nestx = opf.xpath(ix, ns);
+ if(nestx.size()>0) items.push_back(nestx[0]);
+ }
delete ns;
return true;
View
@@ -11,6 +11,8 @@
#include "Ebook.h"
#include "Zip.h"
+#include <vector>
+#include <string>
class Epub : public Ebook {
public:
@@ -22,6 +24,8 @@ class Epub : public Ebook {
Epub() {};
bool check();
Zip * zf;
+ std::vector<std::string> items, resources;
+ std::string base;
};
#endif /* EPUB_H */
View
@@ -7,7 +7,6 @@
*/
#include "Xml.h"
-#include <iostream>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
@@ -17,7 +16,6 @@ bool Xml::initDone = Xml::doInit();
bool Xml::doInit() {
xmlInitParser();
- std::cerr << "Init done." << std::endl;
return true;
}

0 comments on commit 656cbfb

Please sign in to comment.