iPhone 开发 - XMLParser 与 libxml2 与 TouchXML

发布于 2024-07-10 20:47:04 字数 53 浏览 7 评论 0原文

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

问候。 穆斯塔法

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

Regards.
Mustafa

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伏妖词 2024-07-17 20:47:04

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

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

因此,应该回答的第一个问题是 SAX 与 DOM 问题。 如果您正在处理大型 XML 文件(例如 10 MB 或更大),您可能需要坚持使用 SAX。 如果您正在处理小型 XML 文件或小型 XML 片段,那么使用 DOM 通常会更容易。

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

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

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.

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.

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.

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

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.

第七度阳光i 2024-07-17 20:47:04

请参阅 XML 教程iOS:如何为您的 iPhone 项目选择最佳的 XML 解析器

在 iPhone 上解析 XML 时有很多选择。 iPhone SDK 附带两个不同的库可供选择,还有几个流行的第三方库可用,例如 TBXML、TouchXML、KissXML、TinyXML 和 GDataXML。 开发人员如何为他们的项目选择最好的 XML 解析器?

我最近一直在研究各种选项,最后扩展了 Apple 的 XMLPerformance 示例来尝试上述每个库,以了解它们的工作原理并比较它们的性能。 我想我应该将迄今为止所学到的知识分享给其他可能正在为其 iPhone 项目寻找最佳 XML 库的人。

在本 XML 教程中,我们将详细比较最流行的 iPhone 库的功能和性能,解释如何在它们之间进行选择,并提供一个示例项目,展示如何使用上述每个库读取 XML 数据...

See XML Tutorial for iOS: How To Choose The Best XML Parser for Your iPhone Project:

There are a lot of options when it comes to parsing XML on the iPhone. The iPhone SDK comes with two different libraries to choose from, and there are several popular third party libraries available such as TBXML, TouchXML, KissXML, TinyXML, and GDataXML. How is a developer to choose the best XML parser for their project?

I have been recently taking a look at the various options out there, and ended up extending the XMLPerformance sample from Apple to try out each of the above libraries to learn how they worked and compare their performance. I thought I’d share what I’ve learned thus far to others who might be searching for the best XML library for their iPhone project.

In this XML tutorial we’ll give a detailed comparison of the features and performance of the most popular iPhone libraries, explain how to choose between them, and give a sample project showing how to read XML data using each of the above libraries...

回首观望 2024-07-17 20:47:04

还有另一个很好的基于块的 XML 解析库 - RaptureXML (github),作者:ZaBlanc,它在 libxml2 之上提供 Objective-C API,我绝对推荐尝试一下。

There is another good block-based XML parsing library - RaptureXML (github) by ZaBlanc , it provide Objective-C API on top of libxml2, I definitely recommend to try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文