iOS Questions and Answers

Types of parsers?

There are various parsers available to parse an XML in iOS app development. You can choose either from iOS SDK provided by Apple or from third party libraries. Before discussing about various options, I want to highlight difference between XML parsers. Generally two types of parsers are used in XML parsing: SAX and DOM. Let’s have a look at their brief description.

SAX parser- This parser is based on some notifying methods. These methods are notified as the SAX parser moves on the XML document. During the parsing activity, developer is responsible to construct required object and keep track of state of the XML parser. Some examples of this parser are as follows-

NSXMLParser – It is written in Objective-C and provided by Apple through its iOS SDK.

libxml2 – It is based on C language API and also provided by Apple through its iOS SDK. It supports both SAX and DOM parser.

DOM parser- This parser parse the complete document in a single go and converts it into a specific structured object. We can create XPath query for a particular element from this structured object. Some examples of this parser are as follows-

TBXML- It’s a lightweight XML parser designed in such a way to consume very low memory. It’s a good choice for an XML as well as that have the fixed structure.

TouchXML – It is another DOM parser. It is also read only but does not support XPath queries.

KissXML – It is based on TouchXML parser. It supports editing and writing XML unlike TouchXML parser.

TinyXML – It is very small DOM parser and based on C language API. It supports editing and writing XML documents like KissXML parser but does not support XPath queries.

GDataXML – It is developed by Google using Objective-C API. It supports both editing of XML documents and XPath queries.