Created
August 7, 2013 13:35
-
-
Save odrobnik/6174084 to your computer and use it in GitHub Desktop.
replacing HTML entities with libxml2's SAX HTML Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 & 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