Re: Trouble getting ISO-8859-1 encoded feed to parse and display
Re: Trouble getting ISO-8859-1 encoded feed to parse and display
- Subject: Re: Trouble getting ISO-8859-1 encoded feed to parse and display
- From: Diederik Meijer | Ten Horses <email@hidden>
- Date: Mon, 24 Nov 2014 18:20:07 +0100
Verstuurd vanaf mijn iPhone
> Op 24 nov. 2014 om 04:13 heeft Keary Suska <email@hidden> het volgende geschreven:
>
>> On Nov 23, 2014, at 11:06 AM, Diederik Meijer | Ten Horses <email@hidden> wrote:
>>
>> I am having trouble getting useful data from this url on some, but not all, iOS devices:https://www.taxpublications.deloitte.co.uk/tis/dtp.nsf/pub1.xml
>>
>> The feed has this opening tag: <?xml version="1.0" encoding="ISO-8859-1" ?>
>>
>> When I just pull in the feed’s contents using a NSURLConnection, it will show up on some, but not all, devices.
>>
>> When I try to log the response data, by creating a string that I init with the downloaded data and NSUTF8StringEncoding, the log will show a null string. So putting the downloaded data into a string using UTF8 doesn’t work.
>>
>> NSString *dataString = [[NSString alloc] initWithData:self.dataContainer encoding:NSUTF8StringEncoding];
>
> The above code is wrong in your case. The second parameter must be the encoding that the characters are currently in, not the encoding you want NSString is--at least outwardly--encoding-agnostic. It doesn't care what you feed into it, it will always spit out UTF8 unless you specify otherwise.
Agreed
>
>> Still, in that case, some devices will show the parsed feed, some won’t.
>
> Separating the erros in your debugging attempts vs what might actually be happening is more useful at the moment.
Agreed, but I have no clear errors
>
>> I tried converting the data into NSISOLatin1 and then putting it back into NSData using UTF8, as below, but that doesn’t help.
>
> This would be entirely pointless, as the XML parser shouldn't care what character encoding is used, as long as it is declared. UTF8 is magical for the parser.
>
>> -(void)connectionDidFinishLoading:(NSURLConnection *)connection {
>> NSString *dataString = [[NSString alloc] initWithData:self.dataContainer encoding:NSISOLatin1StringEncoding];
>
> This line is the proper way to convert the data into a string. You can then NSLog() with impunity. I would also include the data length, just to make sure that a nil result is not due to empty or nil data.
>
Will try this, thanks
>> [self setDataContainer:[[dataString dataUsingEncoding:NSUTF8StringEncoding] mutableCopy]];
>> self.xmlItems = [NSMutableArray array];
>> NSXMLParser *parser = [[NSXMLParser alloc] initWithData:self.dataContainer];
>> [parser setDelegate:self];
>> [parser parse];
>> }
>>
>>
>> I validated the feed’s XML and got no errors..
>
> HTH,
>
> Keary Suska
> Esoteritech, Inc.
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden