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

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

问题描述

我无法找到这些解析技术的比较。哪一个最常用?

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

问候。
Mustafa

Regards. Mustafa

推荐答案

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

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