最大尺寸与DOM解析XML时 [英] Maximum size when parsing XML with DOM

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

问题描述

目前我正在执行一个REST客户端,它应解析XML响应消息。它的目的是,以后,要在Android设备上运行。因此,内存和处理速度是相当的问题。但会有在同一时间只有一个XML响应,以便处理或持有多个XML文档的时间不是问题。

Currently I'm implementing a REST client which shall parse the XML response messages. It is intended, later, to be running on an Android device. Thus, memory and processing speed is quite an issue. However there will be only one XML response at a time so processing or holding multiple XML documents at a time is not an issue.

由于FAS我的理解有三种方法解析XML与Android SDK的:

As fas as I understood there are three ways of parsing XML with the Android SDK:

  • SAX
  • XmlPullParser
  • DOM

阅读有关我得到的SAX这些不同的分析方法,建议大的XML文件,因为它不会保持完整的树在内存中(如DOM)。

Reading about these different parsing methods I got that SAX is recommended for large XML files as it won't hold the complete tree in memory like DOM.

不过,我问自己,什么是大的千字节,兆字节计算,...?是否有一个实际的尺寸可达它其实并不重要无论是使用SAX或DOM?

However, I'm asking myself what is large in terms of kilobytes, megabytes, ...? Is there a practical size up to which it does not really matter whether using SAX or DOM?

谢谢,
罗伯特·

Thanks,
Robert

推荐答案

有XML文档或DOM尺寸设置没有标准的限制,因此完全取决于主机可以应付一下。

There are no standard limits set for XML documents or DOM size so it depends entirely on what the host machine can cope with.

由于要实现在Android上,你应该承担的内存pretty的数量有限,并记住DOM,XML解析器,你的程序逻辑,显示逻辑,在JVM和Android本身都纷纷以适应可用内存!

As you are implementing on Android you should assume a pretty limited amount of memory, and remember the DOM, the XML parser, your program logic, the display logic, the JVM and Android itself all have to fit in the available memory!.

作为一个经验法则,你可以期望的DOM占用内存约源XML文档的四倍。因此,假设可用内存512MB,目的是采取不超过一半的为您DOM和你结束了8分之512或实际最​​大为64​​MB的XML文档。

As a rule of thumb you can expect the DOM occupy memory about four times the size of the source XML document. So assume 512MB of available memory, aim to take no more than half of this for you DOM and you end up with 512/8 or a practical maximum of 64MB for the XML doc.

只是为了安全起见,我想一半,再一个32MB最大。因此,如果你希望这种规模的许多文件,我会swithc到SAX解析!

Just to be on the safe side I would half that again to a 32MB max. So if you expect many documents of this size I would swithc to SAX parsing!.

如果您希望应用程序与大型文档的任何速度响应SAX是要走的路。 SAX解析器可以立即开始返回结果的第一个元素是读一个DOM解析器需要阅读整个文档的任何输出可以被发送到你的程序之前。

If you want the app to respond with any speed on large documents the SAX is the way to go. A SAX parser can start returning results as soon as the first element is read a DOM parser needs to read the whole document before any output can be sent to your program.

这篇关于最大尺寸与DOM解析XML时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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