Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An objective c wrapper around libxml for parsing HTML
Latest commit 8d417e2 @zootreeves Merge pull request #15 from larsw/ARC
Fixed for ARC
Failed to load latest commit information.
HTMLNode.h Cleaned up header
HTMLNode.m Fixed for ARC
HTMLParser.h [HTMLParser head] for convenience
HTMLParser.m Fixed for ARC Include example in README

  1. Open Your project in XCode and drag and drop all .h & .m Files into an appropriate folder
  2. In the project settings add "/usr/include/libxml2" to the "header search paths" field
  3. Ctrl Click the Frameworks group choose Add -> Existing Frameworks and from the list choose libxml2.dylib

Example Usage

NSError *error = nil;
NSString *html =
        "<li><input type='image' name='input1' value='string1value' /></li>"
        "<li><input type='image' name='input2' value='string2value' /></li>"
    "<span class='spantext'><b>Hello World 1</b></span>"
    "<span class='spantext'><b>Hello World 2</b></span>";
HTMLParser *parser = [[HTMLParser alloc] initWithString:html error:&error];

if (error) {
    NSLog(@"Error: %@", error);

HTMLNode *bodyNode = [parser body];

NSArray *inputNodes = [bodyNode findChildTags:@"input"];

for (HTMLNode *inputNode in inputNodes) {
    if ([[inputNode getAttributeNamed:@"name"] isEqualToString:@"input2"]) {
        NSLog(@"%@", [inputNode getAttributeNamed:@"value"]); //Answer to first question

NSArray *spanNodes = [bodyNode findChildTags:@"span"];

for (HTMLNode *spanNode in spanNodes) {
    if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"spantext"]) {
        NSLog(@"%@", [spanNode rawContents]); //Answer to second question

[parser release];
Something went wrong with that request. Please try again.