Solution for: #42: HTML or XHTML Parser for iPhone SDK 2.x

Hpple: a simple XML/HTML parser that works on iPhone

5
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:

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?

Comments

  1. 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 UTC
  2. wt is the string(//a[@class='sponsor']) u passed for search function

    rev on September 04, 2009, 11:52 AM UTC
  3. it's an XPath for finding nodes in XHTML ( http://www.w3schools.com/XPath/xpath_syntax.asp ).

    92049143cabb7ba896d7c06e19906303_small yliu on October 30, 2009, 01:35 AM UTC