views:

96

answers:

4

i want to display output of html file without using uiwebview.please give some sample code to parse html file............thanks in advance

A: 

You don't need to parse the HTML. The UIWebView will display it for you.

You need only to tell what URL the UIWebView should open and it will do the job.

UIWebView *webView = [[UIWebView alloc] initWithFrame:someFrame];
[webView loadRequest:[NSURLRequest requestWithURL:urlToBeLoaded]];
[self.view addSubview:webView];
[webView release];

For more info have a look at the UIWebView Class Reference. Have a look also at the recomended sample codes on that same link.

vfn
i already know that...my task is to parse the html and display it in other controls........give sample code for html parsing.
You could try XPath or NSXMLParser. What would you do with the HTML? Could you edit your question with an example of what you want to achieve?
vfn
A: 

Why wouldn't you want to use a UIWebView? If you want to load a local file, you can just do this:

NSString *htmlstr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"filename" ofType:@"HTML"] encoding:NSUTF8StringEncoding error:nil];
[web loadHTMLString:htmlstr baseURL:[NSURL URLWithString:@"http://localhost/resources"]];

This is the way I would suggest doing this, because users are familiar with the way that the UIWebView is used.

Richard J. Ross III
that's my task.i have to use control other than webview .... give code without using webview
So it's homework? Then tag it as such!
Richard J. Ross III
A: 

libxml has a sister parser to xmlparser, htmlparser -- it's a SAX style callback like xmlparser -- but doesn't assume that the data is strict XML format.

HTMLParser.h header makes this claim * Summary: interface for an HTML 4.0 non-verifying parser * Description: 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.

This only takes care of the parsing - if you want rich text display, then you will need to build your own rich text viewer - on iOS 3.2+ there's CoreText - but it's fairly low level code to write still. Three20 has a TTextView which you could maybe look at - but it isn't a drop in solution either.

What is the complexity of the HTML you want to display?

Todd
+5  A: 

Short answer

not possible.

Long answer

it's possible, but you don't want to go there. You're basically asking "how can I write my own HTML rendering engine", which while theoretically possible, is practically impossible for one person. Also, given that you're asking this question on how to parse HTML in the first place, I'm going to assume that you don't have the programming skills that would be required to do this. Heck, I've been programming for over a decade and I'd never try doing that, because someone has already done it for me. It's called a UIWebView, and it's a matter of 1 or 2 lines to display HTML in a webview, versus the tens of thousands of lines it would take to write one yourself. (And by the way, asking us to write it for you does not endear you to us)

Here's the question you should be asking:

I need to display HTML, but I don't want the default behavior of a UIWebView. Instead I need <this> and <this> and <this>. How can I adapt a UIWebView to do what I need?

Dave DeLong
I suspect the answer is "I need to display HTML, but I don't wantto use UIWebView because that's what my professor said I should do to get good marks"
Roger Nolan