Tree XML parser for iPhone

When parsing XML files, there are two ways. One is to use an event parser and the other one is to use a tree parser. Cocoa provides classes for the two different type of parsing. NSXMLDocument provides a tree parser functionality while NSXMLParser provides an event parser functionality.

However, for devices like iPhone where memory usage is critical, using tree parser is not recommended. I guess that is why Apple doesn’t provide NSXMLDocument on iPhone/iPod touch.

However, the model of event parsing may not be acceptable by your code. You may need to use XPath/XQuery.
Then the underlying open source library, libxml2 can provide the functionality, but you want Cocoa style approach.

At Cocoa with Love, very nice explanation and code sample to write wrapper for the libxml2 was posted. It has a title, “Using libxml2 for XML parsing and XPath queries in Cocoa”

Also, there are two tree XML parsers for iPhone.

Also at StackOverFlow, there is a very nice explanation why using tree parsers on mobile device is not good. Although your iPhone/iPod touch may have plenty of memory space, due to its origin ad the fact that it is mobile device, I think the explanation still holds.

One response to this post.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: