iPhone Development - XMLParser vs. libxml2 vs. TouchXML

徘徊边缘 提交于 2019-11-26 23:44:36

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.

Andrew Kovzel

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...

danylokos

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!