I am developing an iOS app for iPhone. I am getting json data from a url.
Now, the data contains html tags which i want to parse, I an using Hpple lib to do so.
Being new to ios development, I am not able to figure out how to do so.
Data contains anchor and img tags from which i want to extract information. Also, I want to keep the format of the data as it is ( by parsing paragraph, blockquotes, strong etc... tags).
and display respective content dynamically (depending on the json data).
Obj C code that i am using to parse html:
Tutorial.h
@interface Tutorial : NSObject
@property (nonatomic, copy) NSString *url;
@end
Tutorial.m
@implementation Tutorial
@synthesize url = _url;
@end
DetailViewController.m
-(void)loadTutorials {
//_DetailModal1[3] contain html source code.
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:_DetailModal1[3]];
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];
NSString *tutorialsXpathQueryString = @"//a/";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
Tutorial *tutorial = [[Tutorial alloc] init];
[newTutorials addObject:tutorial];
tutorial.url = [element objectForKey:@"href"];
}
objects = newTutorials;
[self.textView reloadData];
}
xcode : 5.1
ios version : 7.0 and above
I previously had the same issue and found a solution using NSScan