Re: Converting an HTML source string to a readable string
Re: Converting an HTML source string to a readable string
- Subject: Re: Converting an HTML source string to a readable string
- From: Eric Morand <email@hidden>
- Date: Fri, 12 May 2006 11:23:39 +0200
Also note that regular string encodings will not (AFAIK) handle
HTML character encodings for you. To do that, you might be able to
use the functionality provided by NSAttributedString (in the
AppKit additions). Init an attributed string with your HTML data,
and then grab a plain NSString from this attributed string.
The problem is that the NSAttributedString additions methods loose
the HTML tags in the process (which is exactly what they are supposed
to do). And I need them to parse the content of the page.
Or perhaps there's functionality in WebKit to do this?
Thanks for the tip. I'll try to find something there.
Le 12 mai 06 à 08:46, j o a r a écrit :
On 12 maj 2006, at 08.28, Eric Morand wrote:
I've tried to convert the string with various encoding, using :
MyString = [NSString stringWithContentsOfURL:[NSURL
URLWithString:@"http://www.gamekult.com/communaute/chat/"]];
NSData * data = [MyString
dataUsingEncoding:NSUnicodeStringEncoding allowLossyConversion:YES];
MyString = [[NSString alloc] initWithData:data
encoding:NSUnicodeStringEncoding];
But it doesn't change anything.
You're doing unnecessary, and probably incorrect, conversions. Go
to NSData first, and then to NSString using an explicit encoding:
NSData *data = [NSData dataWithContentsOfURL: theURL];
NSString *string = [[[NSString alloc] initWithData: data encoding:
NSISOLatin1StringEncoding] autorelease];
Note however, that this will not solve your problem unless you
happen to find out the correct encoding to use! Don't use
NSUnicodeStringEncoding (or any other encoding) unless you're
_sure_ it's the right one!
Also note that regular string encodings will not (AFAIK) handle
HTML character encodings for you. To do that, you might be able to
use the functionality provided by NSAttributedString (in the AppKit
additions). Init an attributed string with your HTML data, and then
grab a plain NSString from this attributed string.
Or perhaps there's functionality in WebKit to do this?
j o a r
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden