Skip to content
This repository
Browse code

Include example in README

Convert formatting to Markdown.
  • Loading branch information...
commit 401aa333b442c31e4db07f09c9104276f5ff61d0 1 parent d58b03e
Max Howell mxcl authored

Showing 2 changed files with 42 additions and 3 deletions. Show diff stats Hide diff stats

  1. +0 3  README
  2. +42 0 README.md
3  README
... ... @@ -1,3 +0,0 @@
1   -1. Open Your project in XCode and drag and drop all .h & .m Files into an appropriate folder
2   -2. In the project settings add "/usr/include/libxml2" to the "header search paths" field
3   -3. Ctrl Click the Frameworks group choose Add -> Existing Frameworks and from the list choose libxml2.dylib
42 README.md
Source Rendered
... ... @@ -0,0 +1,42 @@
  1 +1. Open Your project in XCode and drag and drop all .h & .m Files into an appropriate folder
  2 +2. In the project settings add "/usr/include/libxml2" to the "header search paths" field
  3 +3. Ctrl Click the Frameworks group choose Add -> Existing Frameworks and from the list choose libxml2.dylib
  4 +
  5 +Example Usage
  6 +=============
  7 +```objc
  8 +NSError *error = nil;
  9 +NSString *html =
  10 + @"<ul>"
  11 + "<li><input type='image' name='input1' value='string1value' /></li>"
  12 + "<li><input type='image' name='input2' value='string2value' /></li>"
  13 + "</ul>"
  14 + "<span class='spantext'><b>Hello World 1</b></span>"
  15 + "<span class='spantext'><b>Hello World 2</b></span>";
  16 +HTMLParser *parser = [[HTMLParser alloc] initWithString:html error:&error];
  17 +
  18 +if (error) {
  19 + NSLog(@"Error: %@", error);
  20 + return;
  21 +}
  22 +
  23 +HTMLNode *bodyNode = [parser body];
  24 +
  25 +NSArray *inputNodes = [bodyNode findChildTags:@"input"];
  26 +
  27 +for (HTMLNode *inputNode in inputNodes) {
  28 + if ([[inputNode getAttributeNamed:@"name"] isEqualToString:@"input2"]) {
  29 + NSLog(@"%@", [inputNode getAttributeNamed:@"value"]); //Answer to first question
  30 + }
  31 +}
  32 +
  33 +NSArray *spanNodes = [bodyNode findChildTags:@"span"];
  34 +
  35 +for (HTMLNode *spanNode in spanNodes) {
  36 + if ([[spanNode getAttributeNamed:@"class"] isEqualToString:@"spantext"]) {
  37 + NSLog(@"%@", [spanNode rawContents]); //Answer to second question
  38 + }
  39 +}
  40 +
  41 +[parser release];
  42 +```

0 comments on commit 401aa33

Please sign in to comment.
Something went wrong with that request. Please try again.