views:

355

answers:

2

Hi all,

I would like to know some libraries in objective-C for xml parsing. I think it is a very common need, but I found limited resources for handling this task:

What is your best solution to work with XML in objective-C language? Please advice.

What is the solution that you have used for your product?

A: 

It serves a narrow purpose, but if your goal is to parse untidy HTML, you might want to try a static library I started called TagScraper. It doesn't handle many/most XML/HTML entities correctly, but it could be pretty easily patched to. URL: http://github.com/searls/TagScraper

Its value is that it provides a simple XPath mechanism that hides the tidying/querying/assembling for you, and then it provides the parsed elements & attributes in a tree-like data structure of Tag.h nodes.

Justin Searls
+2  A: 

NSXMLParser is a stream-oriented class; you set it up and get delegate callbacks when it detects something. Usually this is not what you want to do, but can be much faster and lower memory.

TouchXML will parse the XML itself using libxml, and create an object tree for the entire XML structure. This allows you to easily access the contents of the XML tree, using manual traversal methods or basic XPaths (more sophisticated XPath support is planned).

Steve Streza
Hi Steve, I know these two resources for learning touchxml and libxml2. Do you have some more to share with us?TouchXML tutorial: http://dblog.com.au/general/iphone-sdk-tutorial-building-an-advanced-rss-reader-using-touchxml-part-1/libxml2 tutorial: http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
sfa
Not sure about using libxml2 directly. TouchXML was designed to be a replacement implementation for the NSXML* classes in most cases, so you can look at the Mac-specific documentation for the class you need in TouchXML (e.g. CXMLDocument->NSXMLDocument, CXMLElement->NSXMLElement, CXMLNode->NSXMLNode, etc.).In general, you simply need to create an CXMLDocument object with the XML you need. Then, you can query the root element, either using manual traversal (using childAtIndex:) or using XPath and -[CXMLNode nodesForXPath:error:].Hope that helps!
Steve Streza