On 5.5.2008, at 22:41, Ricky Sharp wrote:


On May 5, 2008, at 2:53 PM, Robert Cerny wrote:

I use NSXMLDocument to parse web page content, which is in NSWindowsCP1250Encoding. However I don't get correctly encoded data from NSXMLNodes

NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSData *webData = [NSURLConnection sendSynchronousRequest:req
                                   returningResponse:&response
                                           error:&error];
doc = [[NSXMLDocument alloc] initWithData:webData
                                options:NSXMLDocumentTidyHTML
                                  error:&error];
[doc setCharacterEncoding:@"windows-1250"];

does anyone have an idea what's wrong?


You're going to have to provide more detail. For example, given a starting string, how is it getting mangled?

The best thing to do for encoding issues is to divide and conquer to see where there problem(s) is/are.

For example, how exactly is the data from the web-site handled? e.g. does the URL point directly to an XML file? Is there something about the HTTP header that is specifying the wrong encoding?

Is there an encoding attribute in the XML file itself?
___________________________________________________________
Ricky A. Sharp         mailto:[EMAIL PROTECTED]
Instant Interactive(tm)   http://www.instantinteractive.com


Hi,
thanks for your reply. My URL is a standard HTML (php based) web page which I need to parse to gather some data. It's in XHTML Transitional coding, lang defined as 'cs': <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="cs" lang="cs">
<meta http-equiv="content-type" content="text/html; charset=windows-1250" />


When I get contents of URL as NSData and convert it to [NSString initWithData:(NSData *)data encoding:(NSStringEncoding)encoding] and provide NSWindowsCP1250Encoding, I get correct result.

Robert

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to