如何加速Android XML解析? [英] How Can I Speed Up Android XML Parsing?

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

问题描述

下午好(取决于你居住的地方)!

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解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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