Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created August 7, 2013 13:35
Show Gist options
  • Save odrobnik/6174084 to your computer and use it in GitHub Desktop.
Save odrobnik/6174084 to your computer and use it in GitHub Desktop.
replacing HTML entities with libxml2's SAX HTML Parser
#import "AppDelegate.h"
#import "ViewController.h"
#import "DTHTMLParser.h"
@interface AppDelegate () <DTHTMLParserDelegate>
@end
@implementation AppDelegate
{
NSString *_convertedString;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *string = @"Some text &amp; some entities";
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
DTHTMLParser *parser = [[DTHTMLParser alloc] initWithData:data encoding:NSUTF8StringEncoding];
parser.delegate = self;
BOOL b = [parser parse];
NSLog(@"converted %@", _convertedString);
// ...
}
- (void)parser:(DTHTMLParser *)parser foundCharacters:(NSString *)string
{
_convertedString = [string copy];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment