The SDK provides two methods for parsing XML: libxml2 and NSXMLParser. libxml2 is the fastest. To use it in your project, go to the build settings for your iPhone App project and set the following:
Other linker flags = -lxml2Header Search Paths: $(SDKROOT)/usr/include/libxml2
Then download XPathQuery.m and XPathQuery.h from this page: Using libxml2 to parse XML and XPath queries in Cocoa , which also provides a tutorial on how to use it. This XPathQuery class is a simplified way to parse XML. I recommend it if you do not want to write the same code yourself, which does not look like this.
With this in place do
NSString *string = nil; // put your html document here NSData *htmlData = [string dataUsingEncoding:NSUTF8StringEncoding]; NSString *xpath = @"//row"; // any standard XPath expression NSArray *nodesArray = PerformHTMLXPathQuery(htmlData, xpath); NSDictionary *dict; if (0<[nodesArray count]) { dict = [nodesArray objectAtIndex:0]; }
At this point, the elements from your document should be inside the dict dictionary.
source share