Solution for: #42: HTML or XHTML Parser for iPhone SDK 2.x
Hpple: a simple XML/HTML parser that works on iPhone
- yliu on May 15, 2009, 10:11 PM UTC
As linked from the reference section, hpple provides an easy interface for tolerant XML/XHTML parsing from Objective-C on the iPhone SDK 2.x & 3.x
You'll need to include libxml and its headers into your iPhone project, and also pull in the three Hpple classes: TFHpple, TFHppleElement, and XPathQuery. Then, it's a nice and simple:
Simple as that. If you've worked with Hpricot in Rails, there is a very similar interface. And no need to pay for any licenses.
It's classified as an experimental project by the developer, but so far it's "worked for me"
UPDATE: seems to be kinda broken now. Anyone got a better solution?
You'll need to include libxml and its headers into your iPhone project, and also pull in the three Hpple classes: TFHpple, TFHppleElement, and XPathQuery. Then, it's a nice and simple:
TFHpple * doc = [[TFHpple alloc] initWithHTMLData:data];
NSArray * elements = [doc search:@"//a[@class='sponsor']"]; // XPath, woohoo!
Simple as that. If you've worked with Hpricot in Rails, there is a very similar interface. And no need to pay for any licenses.
It's classified as an experimental project by the developer, but so far it's "worked for me"
UPDATE: seems to be kinda broken now. Anyone got a better solution?
References used:
Adding the libXML framework to your iPhone App | Wulf
( http://welcome.totheinter.net/2008/03/11/adding-the-libxml-framework-to-your-iphone-app/ ) - found by yliu on May 07, 2009, 01:12 PM UTC
topfunky's hpple at master - GitHub
( http://github.com/topfunky/hpple/tree/master ) - found by yliu on May 07, 2009, 01:15 PM UTC
Comments
You could also check HyperParser. It's a simple HTML parser that has API similar to NSXMLParser. Designed specially to parse semi-valid HTML. http://www.dimzzy.com/index.php?page=hyper-parser
— dimzzy on August 11, 2009, 12:40 AM UTCwt is the string(//a[@class='sponsor']) u passed for search function
— rev on September 04, 2009, 11:52 AM UTCit's an XPath for finding nodes in XHTML ( http://www.w3schools.com/XPath/xpath_syntax.asp ).
— yliu on October 30, 2009, 01:35 AM UTC