下午好(取决于你住在哪里)!
Good afternoon (depending on where you live)!
我对 Android 开发还很陌生,目前我正在努力将功能从现有的 iOS 应用程序转移到 Android 上.此功能的一部分是解析包含大约 500 个条目的大"(约 13,000 行)RSS XML 文件.我花了 10 到 15 个小时研究 Android 上的 XML 解析并尝试了主要的 XML 解析器:DOM、SAX 和 Pull-parsing.这是我的结果,在我的机器上的模拟器中运行(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 分钟,但在我对该实现进行编码时没有计时.
DOM: Greater than 4:00 minutes, but didn't time it when I had that implementation coded.
我也试过这个来自 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 的实现都取自 stackoverflow.com 线程,所以我很有信心我没有在其中做任何非标准的事情(不过,我不排除这种可能性).我决定吸引更多、更有经验的人群来了解我还可以尝试什么.
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.
我无法控制文件的格式.如果我要实现这种端到端,我只需编写一个 Web 服务,它会在服务器上完成所有繁重的工作,然后发送一个小的、紧凑的 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. :)
对我能做什么有任何见解吗?这似乎是一个相当普遍的问题,但大多数回复只是说尝试使用不同的主要 XML 解析器之一.就我而言,我已经尝试了所有三个,即使是最快的也似乎太慢了.
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.
我做错了什么?在Android上通过网络进行XML解析时,人们通常会遇到什么正常的新手"问题???
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.
这里有一些基准测试.
此外,模拟器速度极慢,因此请在真实设备上尝试一下,您可能会看到很大的改进.
Also, the emulator is extremely slow, so try it on a real device and you will likely see great improvements.
这篇关于如何加快 Android XML 解析速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!