tags:

views:

1757

answers:

2

Hi,

I am accessing a web page using NSURLConnection and have a HTML data downloaded programmatically in my iPhone client application. I want to parse and pick some description data from the HTML tags..It is too dirty tags and my data is also here and there. I would like to ask you, is there a standard or easy way of parsing of HTML data on iPhone development. P.S: I know about XML parsing.

thanks.

Clave/

A: 

libxml2.2 comes in the SDK, and libxml/HTMLparser.h claims the following:

This module implements an HTML 4.0 non-verifying parser with API compatible with
the XML parser ones. It should be able to parse "real world" HTML, even if
severely broken from a specification point of view.

It shouldn't be too difficult to use that, but if all else fails you could always load up a UIWebView in the background and have it load the content for you.

rpetrich
Thank you. I'll go through it. Can i analyze some sample code available somewhere?
Clave Martin
I don't have any sample code handy, but you should be able to get by with the reference documentation: http://veillard.com/XML/html/libxml-HTMLparser.html; I would start with the htmlReadMemory function and move from there :)
rpetrich
I also have one more question: As i know the HTML page link in my iPhone client app, can't i launch the same page directly using UIWebView or something in my application itself, instead of parsing the HTML data etc process and then trying to view the data?thanks.
Clave Martin
Any advice please for my above comment? Is it possible to access and load a web page directly in my iPhone client application view without launching web browser (or) parsing and loading the HTML data?
Clave Martin
I'm not sure what you're asking. If you want to just display a webpage inside of your application, UIWebView will do. If you want to extract data from HTML you have retrieved over HTTP, you can use libxml or have UIWebView do the work for you
rpetrich
A: 

hey i tried to parse html file by using HTMLParser class but contents is returning "NULL" here is the code:

HTMLParser * parser =[[HTMLParser alloc] initWithContentsOfURL:[NSURL fileURLWithPath[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"chapter-001.xml"]] error:error];

if (error)
{
    NSLog(@"Error: %@", error);
    return ;
}

HTMLNode *htmlnode = [parser html];

NSLog(@"%@",[htmlnode contents]);

Please can any one help me :)

Chralie