iPhone 开发 - XMLParser vs. libxml2 vs. TouchXML [英] iPhone Development - XMLParser vs. libxml2 vs. TouchXML

查看:10
本文介绍了iPhone 开发 - XMLParser vs. libxml2 vs. TouchXML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到这些解析技术的比较.哪一种最常用?

I cannot find comparison of these parsing technique. Which one is most commonly used?

问候.穆斯塔法

推荐答案

NSXMLParser 是一个 SAX解析器,这意味着它遍历 XML 文档,并(通过委托方法)通知您各种事件(例如启动 xml 节点、查找属性等).这种类型的 XML 处理最适合解析大型文档,并且只需要从大文件中检索少量数据.

NSXMLParser is a SAX parser, meaning it steps through the XML document, and informs you (via delegate methods) of various events (such as starting an xml node, finding attributes, etc). This type of XML processing is best for parsing huge documents, and when you only need to retrieve a tiny amount of data from a big file.

与 SAX 不同的是 DOM 模型,其中整个 XML 树被解析到内存中(通常只需一次调用),然后您就可以从提供的 API 中自由探索 XML 文档.这通常更容易使用,因为您可以随机访问整个 xml 文档.

In contrast to SAX is the DOM model, where the entire XML tree is parsed into memory (usually with a single call), and then you can freely explore the XML document from the presented API. This is generally much easier to work with, as you get random access to the entire xml document.

所以第一个应该回答的问题是 SAX 与 DOM 的问题.如果您正在处理大型 XML 文件(例如 10 MB 或更大),您可能希望坚持使用 SAX.如果您正在处理小型 XML 文件或微小的 XML 片段,则使用 DOM 通常要容易得多.

So the first question one should answer is the SAX vs DOM question. If you're woring with big XML files (say 10 MB or bigger), you may want to stick with SAX. If you're working with small XML files, or tiny XML fragments, it's often much easier to use DOM.

如果您确实决定使用 DOM,您有几个选择.

If indeed you decide to go with DOM, you've got a few options.

libxml2 是一个用 C 语言编写的非常强大的 API.它主要用于 DOM 样式,但如果您有经验,还有其他选择.但是,由于它是用 C 编写的,因此对于那些更熟悉 Objective-C(对象和自动释放)或来自 .Net 世界的人来说,它通常不具有吸引力.因此,需要/渴望一个围绕 libxml 的原生 Objective-C 包装器,以使其更加熟悉.TouchXML 就是这样一种包装器.如果您只需要对 XML 的读取权限,它就可以很好地工作.如果您想更改 XML,或从头开始创建 XML 片段/文档,我建议您使用 KissXML.

libxml2 is a very powerful API written in C. It's mainly for DOM style use, but has other options if you become experienced with it. But, as it's written in C, it's not often attractive to those more familiar with Objective-C (objects, and autorelease), or those coming over from the .Net world. Thus, there is a need/desire for a native Objective-C wrapper around libxml to make it more familiar. TouchXML is one such wrapper. It works well if you only need read access to the XML. If you want to alter the XML, or create XML fragments/documents from scratch, I'd recommend going with KissXML.

这篇关于iPhone 开发 - XMLParser vs. libxml2 vs. TouchXML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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