解析圣经Android的最佳方法 [英] Best way to parse the Bible in Android

查看:175
本文介绍了解析圣经Android的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个Android应用程序需要访问的圣经。我想这是离线的,所以preFER不使用互联网API之一。看完这个<一href="http://stackoverflow.com/questions/4687862/whats-the-best-way-to-store-the-bible-in-sql">this后,我决定在本地存储文本为XML,像这样

I am creating an Android app that needs to access the Bible. I want it to be offline, so I prefer not to use one of the internet APIs. After reading this this post, I decided to store the text locally as XML, like this

<bible>
<b n="Genesis">
<c n="1">
<v n="1">In the beginning, God created the heavens and the earth.</v>

我的问题是,该文件几乎是34000行代码(4.4 MB),它需要很长的时间(几分钟)来解析整个文本。

My problem is that the file is almost 34,000 lines long (4.4 MB) and it takes a LONG time (a few minutes) to parse the entire text.

现在,我使用XmlPullParser,像这样

Right now I'm using the XmlPullParser, like this

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();

InputStream iStream = getResources().openRawResource(R.raw.bible);
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
xpp.setInput(reader);

int eventType = xpp.getEventType();

while (eventType != XmlPullParser.END_DOCUMENT)
{
    // do something here
    eventType = xpp.next();
}

有没有更好的方式来存储和/或访问本地圣经Android上?

我已经考虑存储为多个XML文件解析它快(每本书一个单独的文件),但将preFER不如果可能的话。

I've considered storing it as multiple XML files to parse it faster (a separate file for each book) but would prefer not to if possible.

我愿意接受任何建议,包括存储的文本作为XML相比其他的东西。

I am open to any suggestions, including storing the text as something other than XML.

感谢

推荐答案

我只想用的SQLite 为出发地方,那就是 - 为什么不的? (嗯,确实,现有的库/电子书阅读器/完善的文件架构会更好,但除非是: - )

I would just use SQLite as a "starting place" - that is, why not? (Well, really, an existing library / book reader / well established file schema would even better, but barring that :-)

SQLite的具有非常高效的磁盘上的访问 - 例如,没必要解析,以存储或读取整个文件 - 它支持高效试图对指标(如查找特定的诗句,或在出埃及记让章2到12)。我希望无论是SQLite数据库和原始的XML文件有一个可比的文件大小(假定XML是UTF-8 EN codeD)。

SQLite has very efficient "on disk" access - e.g. no need to "parse" to memory or read an entire file - and it supports efficient seeks over indices (e.g. looking up a specific verse or getting chapters 2 through 12 in Exodus). I would expect both the SQLite database and the original XML file to have a comparable file size (assuming the XML is UTF-8 encoded).

然后使程序/功能装入XML转换成在SQLite数据库适当的模式 - 这是可以做到提前(在PC上如再分发pre-填充SQLite数据库文件)或第一次所述XML被客户端上装载。这可以有效地相同的阅读code,因为它是现在..只是替换做什么与更新数据库。

Then make a program/function to "load" the XML into the appropriate schema in the SQLite database - this can be done ahead of time (e.g. on a PC and then distribute the pre-populate SQLite database files) or the first time said XML is loaded on the client. This can be effectively the same reading code as it is now .. just replace "do something" with "update database".

我会避免分裂,即用文件的方式,除非有特别好的理由 - 这将使它更快地找到特定的章节/节,但它并没有真正解决问题。由于它的使用顺序读取,而不是一个完整的DOM也不会必然导致更少的内存 - 它只是限制垃圾读一遍(然后丢弃),同时寻求。但话又说回来,为什么不的SQLite的?

I would avoid a splitting-of-files approach unless there is a particularly good reason for it - it will make it faster to find a specific chapter/verse, but it doesn't really "solve the problem". Since it's using a sequential reader and not a full DOM it won't necessarily result in less memory - it will just limit the garbage "read over" (and then discarded) while seeking. But then again, why not SQLite?

这篇关于解析圣经Android的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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