Android 开发首选 XML API
我想为 Android 创建一个基本的 RSS feeder 应用程序,但我不知道该选择哪个库: SAX 或 DOM。我应该选择哪个?
有人在 Android 平台上有过使用这两种方法的经验吗? 有什么建议吗?
I want to create a basic RSS feeder app for Android and I don't know which library to choose:
SAX or DOM. Which should I choose?
Does anyone have any experience with either on an Android platform?
Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于 SAX 的解析器将允许您仅存储事件处理程序样式接口所需的信息,而基于 DOM 的方法会将整个文件解析为对象模型。就我个人而言,我会使用 SAX,因为它具有速度和内存优势(尤其是在移动环境中 — 如果您在运行时不知道 XML 的长度,则最终可能会得到一个巨大的模型)。 SAX 允许您根据需要以所需的格式构建自己的对象/信息,而无需在顶部存储默认的对象模型。
不过,一般来说,如果 XML 包含机器可读数据,则基于 SAX 的解析器会很有用;而当您拥有结构化文档样式数据时,基于 DOM 的解析器会很有用。请参阅此处了解更多信息。
A SAX based parser will allow you to store only the information that you require with an event handler style interface, while DOM based methods will parse the whole file into an object model. Personally I would use SAX for both it's speed and memory advantages (especially on a mobile environment --- if you don't know the length of the XML at runtime, you could end up with a huge model). SAX allows you to construct your own objects/information as required in the format you want without having the default object model stored on top.
In general however, a SAX based parser is useful if the XML contains machine readable data, and a DOM based parser is useful when you have structured document style data. See here for more information.
使用SAX解析器,它具有更好的速度和性能......
Use SAX parser, it has better speed and performance....