問題描述
下午好(取決于你住在哪里)!
Good afternoon (depending on where you live)!
我對(duì) Android 開發(fā)還很陌生,目前我正在努力將功能從現(xiàn)有的 iOS 應(yīng)用程序轉(zhuǎn)移到 Android 上.此功能的一部分是解析包含大約 500 個(gè)條目的大"(約 13,000 行)RSS XML 文件.我花了 10 到 15 個(gè)小時(shí)研究 Android 上的 XML 解析并嘗試了主要的 XML 解析器:DOM、SAX 和 Pull-parsing.這是我的結(jié)果,在我的機(jī)器上的模擬器中運(yùn)行(32 位 Windows Vista,2.2 GHz 雙 CPU,3 GB RAM):
I'm fairly new to Android development and I'm currently working on moving the functionality from an existing iOS app to Android. Part of this functionality is to parse a "large" (~13,000 line) RSS XML file that contains about 500 entries. I've spent anywhere from 10-15 hours researching XML parsing on Android AND trying out the major XML parsers: DOM, SAX, and Pull-parsing. Here are my results, running within' the emulator on my box (32-bit Windows Vista, 2.2 GHz Dual CPU, 3 GB RAM):
SAX:~6:00 分鐘
SAX: ~6:00 minutes
拉解析:~4:00 分鐘
Pull-Parsing: ~4:00 minutes
DOM:超過 4:00 分鐘,但在我對(duì)該實(shí)現(xiàn)進(jìn)行編碼時(shí)沒有計(jì)時(shí).
DOM: Greater than 4:00 minutes, but didn't time it when I had that implementation coded.
我也試過這個(gè)來(lái)自 github 的 RSS 閱讀器,但花了 >10:00 分鐘:
I also tried this RSS Reader from github, but it took >10:00 minutes:
https://github.com/matshofman/Android-RSS-Reader-Library
SAX、PP 和 DOM 的實(shí)現(xiàn)都取自 stackoverflow.com 線程,所以我很有信心我沒有在其中做任何非標(biāo)準(zhǔn)的事情(不過,我不排除這種可能性).我決定吸引更多、更有經(jīng)驗(yàn)的人群來(lái)了解我還可以嘗試什么.
The implementations for the SAX, PP, and DOM were all taken from stackoverflow.com threads, so I feel fairly confident that I didn't do anything non-standard in them (though, I'm not ruling that out). I've decided to appeal to a larger, more experienced, crowd to get some ideas of what else I can try.
我無(wú)法控制文件的格式.如果我要實(shí)現(xiàn)這種端到端,我只需編寫一個(gè) Web 服務(wù),它會(huì)在服務(wù)器上完成所有繁重的工作,然后發(fā)送一個(gè)小的、緊湊的 JSON 序列化列表.相反,我有 13K 行文件.:)
I don't have any control over the format of the file. If I was implementing this end-to-end, I would just write a Web Service that did all the heavy-lifting on the server and then sent down a small, compact, JSON-serialized list. Instead, I have the 13K line file. :)
對(duì)我能做什么有任何見解嗎?這似乎是一個(gè)相當(dāng)普遍的問題,但大多數(shù)回復(fù)只是說(shuō)嘗試使用不同的主要 XML 解析器之一.就我而言,我已經(jīng)嘗試了所有三個(gè),即使是最快的也似乎太慢了.
Any insight into what I can do? It seems to be a fairly common problem, but most responses just say to try one of the different main XML parsers. In my case, I've tried all three and even the fastest seems way too slow.
我做錯(cuò)了什么?在Android上通過網(wǎng)絡(luò)進(jìn)行XML解析時(shí),人們通常會(huì)遇到什么正常的新手"問題???
What am I doing wrong? Are there any normal "newbie" problems that people usually encounter when doing XML parsing over the network on Android???
提前感謝您提供的任何幫助!
Thank you in advance for any help you can provide!
推薦答案
使用vtd-xml.
這里有一些基準(zhǔn)測(cè)試.
此外,模擬器速度極慢,因此請(qǐng)?jiān)谡鎸?shí)設(shè)備上嘗試一下,您可能會(huì)看到很大的改進(jìn).
Also, the emulator is extremely slow, so try it on a real device and you will likely see great improvements.
這篇關(guān)于如何加快 Android XML 解析速度?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!