方法来解析XML(org.w3c.Document)在Android方法来、XML、org、Android

2023-09-12 07:17:22 作者:-染勒头发,换勒面。

任何人都可以点我一个解释,或向我解释,我怎么能轻松地解析XML,并使用获得Android上w3c.Document值只有Android操作系统利布斯?

Can anyone point me to a explanation for or explain to me how I can easily parse the XML and get values of a w3c.Document on Android using only Android OS Libs?

我试图用一个实现dom4j的,但它是非常缓慢: - (

I tried to use a implementation of dom4j, but it is very slow :-(

推荐答案

您应该明确地使用所提供的SAX API的。对普通的Java SAX一个顶级的Andr​​oid XML解析API堆栈所以在我看来,我只想用普通的Java SAX API和这种方式,您能测试你的code作为普通的Java桌面项目的能力。

You should definitively use the SAX APIs provided. Android XML parse API stacks on top of the normal java SAX one so in my opinion I would just use the normal Java SAX API and this way you get the ability to test your code as normal java desktop project.

XML解析总是慢和使用这些SAX解析器是因为它得到一样好(除非你写从临时定制的解析器)。 建议道:尽量减少字符串比较,并尝试使用包含HashMap代替长链,如果(token.isEqual(CONSTANT_TOKEN));

XML parsing is always slow and using these SAX parsers is as good as it gets (unless you write a custom parser from the scratch). Word of advice: Try to minimize string comparison and try to use hashmaps instead of long chains of if (token.isEqual(CONSTANT_TOKEN));.

下面是Java XML解析的几个例子:http://java.sun.com/developer/$c$csamples/xml.html#sax

Here are a few examples of Java XML parsing: http://java.sun.com/developer/codesamples/xml.html#sax

Android的XML API是声明,范式是有点不同的,所以如果你决定与该会,是ppared看几个例子,了解它的方式$ P $。

Android XML API is declarative, the paradigm is a bit different so in case you decide going with that, be prepared to read a few examples to learn its ways.

最后,也许2个月前,我看到一个图基准DOM VS SAX和Android手机,XML API(我不能完全找到现在的链接)。得出的结论是,DOM是迄今为止最慢和SAX是顶部,但不是一个巨大的优势超过Android的XML实现。

Finally, maybe 2 months ago I saw a chart benchmarking DOM vs SAX vs Android XML API (I can't quite find the link now). The conclusion was that DOM was by far the slowest and SAX was top but not by a huge margin over Android's XML implementation.