Search code examples
iphonehtml-parsingdeprecatedhpple

hpple html parse iphone sdk help?


I want to parse html.. so I have found some sample code over: http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/ it uses hpple to parse html... but there is one problem this application is constantly crashing for some reason most probably it is this line over here:

NSURL *url = [NSURL URLWithString: @"http://www.objectgraph.com/contact.html"];
NSString *contents = [NSString stringWithContentsOfURL:url];
NSData *htmlData = [contents dataUsingEncoding:NSUTF8StringEncoding];

xCode gives me warning stringWithCOntentsofVariable is deprecated..

so could anyone help me solve this problem....by showing what code should I change?

thanks


Solution

  • 30 seconds in the documentation shows:

    Returns a string created by reading data from the file named by a given URL. (Deprecated in Mac OS X v10.4. Use stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error: instead.)

    So, it looks like you should be using stringWithContentsOfURL:encoding:error or stringWithContentsOfURL:usedEncoding:error: instead.

    Just like the documentation says.