On Nov 23, 2014, at 11:06 AM, Diederik Meijer | Ten Horses 
<diede...@tenhorses.com> 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.

> 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.

> 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.

>    [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 (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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to