Get by Subheader

37 views
Skip to first unread message

Woody NaDobhar

unread,
May 22, 2012, 1:30:37 PM5/22/12
to epublib
In Android, I'm serving up a series of docs who's ToC includes
subheaders (for instance, the 'Introduction' chapter has the
subheadings 'Introduction', 'Thanks', and 'Art Credits'). I've got it
displaying the list of chapters and subheadings with an expandable
list, with each subheading linked to a display activity. Everything's
working fine except I can't seem to figure out how to narrow down my
string from the chapter to just the subheading.

Currently, I've got this to grab the chapter:

String data = book.getContents().get(chapterID).toString(); //works
great for getting the whole chapter.

chapterID and headingID (not shown) are both passed from the expanding
list.

I probably could go into the string and chop it up into what I need,
but I'm hoping the lib has a shortcut that loads just the subheading I
need for the given chapter.

If not, what methodology would you use to get the subheading?

Paul Siegmann

unread,
May 22, 2012, 2:49:11 PM5/22/12
to epu...@googlegroups.com
Hi Woody,

The chapter data is xhtml.
So I would use an xpath expression to get the contents.
There are many tools available to do this.

Does this help ?

regards,
Paul

Woody NaDobhar

unread,
May 22, 2012, 4:11:04 PM5/22/12
to epu...@googlegroups.com
A bit, but I'm new to xPath, so not as much as I'd hoped 8) 

Poking around has got me here:

String data = book.getContents().get(chapterID-1).toString();

XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
NodeList headings = (NodeList) xPath.evaluate("/html/body/*[self::h2]/text()", data, XPathConstants.NODESET);

But it says I have an unknown error in xpath.  What am I missing? And is that the expression I'm looking for?

Heinrik Honculada

unread,
May 22, 2012, 7:54:49 PM5/22/12
to epu...@googlegroups.com
You can actually just use inputstream to get the contents of the books. You are actually close try doing this book.getTableOfContents[Returns a list of resource].get([Specific chapter of your choice input has to be an integer]).getInputStream(); This will return an input stream which then you can decode to produce the proper html string.
Reply all
Reply to author
Forward
0 new messages