Hay,
Recently I made a project where the application need to read the HTML file , parse it and display the data on the view.
Before you start , get the below files from https://github.com/topfunky/hpple
Once you get that, just do the following modifications to your project settings:
1) Goto Target on the left hand side tree. Right click on your project name and hit Get Info option from popup menu.
2) Select All configurations from Configuration combo box.
3) Search for Header Search path and the bloodline with recursive option selected
${SDKROOT}/usr/include/libxml2
4) In the same way, search for Other Linker Flag
add the below line to it:
-lxml2
Here is the code to parse the HTML file. [ This code works for reading local HTML file attached in your project ]
Above code reads all the H1 tags in the HTML page and put them in
which is of type NSArray *.
Please let me know if you have any doubts regarding this.
Recently I made a project where the application need to read the HTML file , parse it and display the data on the view.
Before you start , get the below files from https://github.com/topfunky/hpple
- HTFpple.h
- HTFpple.m
- HTFppleElement.h
- HTFppleElement.m
- XPathQuery.h
- XPathQuery.m
Once you get that, just do the following modifications to your project settings:
1) Goto Target on the left hand side tree. Right click on your project name and hit Get Info option from popup menu.
2) Select All configurations from Configuration combo box.
3) Search for Header Search path and the bloodline with recursive option selected
${SDKROOT}/usr/include/libxml2
4) In the same way, search for Other Linker Flag
add the below line to it:
-lxml2
Here is the code to parse the HTML file. [ This code works for reading local HTML file attached in your project ]
NSMutableArray *array = [[NSMutableArray alloc]init];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"myHTMLfileNameWithoutExtension" ofType:@"html"];
NSData *htmlData = [[NSData alloc] initWithContentsOfFile:filePath];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *chapterName = [xpathParser search:@"//html//h1"]; // get the page title
self.chapterIndexData = chapterName;
[xpathParser release];
[htmlData release];
[array release];
Above code reads all the H1 tags in the HTML page and put them in
chapterIndexData
Please let me know if you have any doubts regarding this.