Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Diederik Meijer | Ten Horses
Op 24 Nov 2014, om 19:01 heeft Jens Alfke  het volgende 
geschreven:

> 
>> On Nov 24, 2014, at 9:30 AM, Diederik Meijer | Ten Horses 
>>  wrote:
>> 
>> I get no errors, but no results from the parser either. I haven't tested 
>> against didStartElement, because it seems clear that no data goes into the 
>> parser.
> 
> Did you implement these delegate methods:
> - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;
> - (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError 
> *)validationError;
> ?

I have now (see below), doesn’t show me anything in the simulator, will test on 
one of the erring devices tomorrow, by the way, both of the following lines log 
the data content out just fine:

NSString *dataString = [[NSString alloc] initWithData:self.dataContainer 
encoding:NSISOLatin1StringEncoding];
NSString *dataString = [[NSString alloc] initWithData:self.dataContainer 
encoding:NSWindowsCP1252StringEncoding];


> 
> I'm pretty sure that NSXMLParser wouldn't fail without returning any sort of 
> error. If it does, you should file a bug report with Apple once you have a 
> reproducible case.
> 
> —Jens
> 



- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"PARSE ERROR IN 
CHANNEL" message:[parseError localizedDescription] delegate:nil 
cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[av show];
NSLog(@"ERROR IN CHANNEL: %@", [parseError localizedDescription]);
}

- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError 
*)validationError {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"VALIDATION ERROR IN 
CHANNEL" message:[validationError localizedDescription] delegate:nil 
cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[av show];
NSLog(@"ERROR IN CHANNEL: %@", [validationError localizedDescription]);
}

___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Jens Alfke

> On Nov 24, 2014, at 9:30 AM, Diederik Meijer | Ten Horses 
>  wrote:
> 
> I get no errors, but no results from the parser either. I haven't tested 
> against didStartElement, because it seems clear that no data goes into the 
> parser.

Did you implement these delegate methods:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;
- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError 
*)validationError;
?

I'm pretty sure that NSXMLParser wouldn't fail without returning any sort of 
error. If it does, you should file a bug report with Apple once you have a 
reproducible case.

—Jens

___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Diederik Meijer | Ten Horses


Verstuurd vanaf mijn iPhone

> Op 24 nov. 2014 om 05:15 heeft Jens Alfke  het volgende 
> geschreven:
> 
> 
>> On Nov 23, 2014, at 1:06 PM, Diederik Meijer | Ten Horses 
>>  wrote:
>> 
>> When I just pull in the feed’s contents using a NSURLConnection, it will 
>> show up on some, but not all, devices.
> 
> What does "show up" mean in this case? Is there an error? If so, what is it?

It means that sometimes the feed is parsed into an NSArray of NSDictionairies 
that is datasource to a UITableView which loads fine, while in other cases no 
data gets shown in the TVC, it stays empty

I get no errors, but no results from the parser either. I haven't tested 
against didStartElement, because it seems clear that no data goes into the 
parser. NSJSONSeriliazation would throw a 'data is nil' error if it were JSON, 
NSXMLParser doesn't seem to do that

Can this be a special characters, "you should escape some of them" issue?

> 
>> 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.
> 
> UTF-8 is a completely different encoding.
> 
>> I validated the feed’s XML and got no errors..
> 
> It's valid XML, but it's got some problems as an RSS feed; take a look at
>   
> http://feedvalidator.org/check.cgi?url=https%3A%2F%2Fwww.taxpublications.deloitte.co.uk%2Ftis%2Fdtp.nsf%2Fpub1.xml
> These are mostly minor, like nonstandard extra elements, but it's also got 
> problems with its date formatting, and also the server reports the 
> Content-Type is ASCII while the XML says it's ISO-8859-1.
> 
> If NSXMLParser is having trouble with the encoding, one problem I've seen 
> before is documents that claim to be ISO-8859-1 while actually being 
> WinLatin, which is a superset with extra characters defined. (The Cocoa 
> encoding name for this is NSWindowsCP1252StringEncoding, IIRC.)
> 

Thanks, will try that

> (I spent four years of my life immersed in RSS feed parsing, and acquired a 
> solid contempt for the ability of the average web developer to construct a 
> valid feed. You would not believe how many messed-up feeds there are in the 
> real world.)
> 
> —Jens
___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Diederik Meijer | Ten Horses


Verstuurd vanaf mijn iPhone

> Op 24 nov. 2014 om 04:13 heeft Keary Suska  het 
> volgende geschreven:
> 
>> On Nov 23, 2014, at 11:06 AM, Diederik Meijer | Ten Horses 
>>  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: 
>> 
>> 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 (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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Jens Alfke

> On Nov 24, 2014, at 5:15 AM, Alex Zavatone  wrote:
> 
> The Android parser doesn't seem to care about return/enter characters, but 
> the iOS JSON parser sure does.  

The grammar at json.org (in the right sidebar on the home page) explicitly says 
strings can't contain control characters. I've had other parsers complain about 
them too, not just Apple's, so this looks like an Android bug.

But then, JSON ≠ XML, so this is off-topic for this thread...

—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-24 Thread Alex Zavatone

On Nov 23, 2014, at 11:15 PM, Jens Alfke wrote:

> (I spent four years of my life immersed in RSS feed parsing, and acquired a 
> solid contempt for the ability of the average web developer to construct a 
> valid feed. You would not believe how many messed-up feeds there are in the 
> real world.)
> 
> —Jens


XML feeds, you say?

On Friday, we ran into an issue where our iOS app produced an obscure error 
when our app was reactivated but our Android app didn't report the same issue.

On iOS, the error that was reported was "control character at position 1072", 
or something to that effect. We were parsing results from a JSON URL, not an 
XML feed.  Well, our server guys put up a JSON file that we simply had to fetch 
from the server, but didn't bother to run it through JSONLint.  What happened 
was that one of out text strings within the JSON was so long, it was scrolling 
off the screen.  Obviously, their editor didn't have this advanced feature 
called line wrap and the person typing in the JSON pressed enter in the middle 
of the line so he could see the whole string.

The Android parser doesn't seem to care about return/enter characters, but the 
iOS JSON parser sure does.  

Fun times when your web guys hand enter the JSON and don't bother to validate 
it.

And this is in a product that was supposed to ship on last Friday.  

Misery obviously loves company.

Cheers,
- Alex
___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-23 Thread Jens Alfke

> On Nov 23, 2014, at 1:06 PM, Diederik Meijer | Ten Horses 
>  wrote:
> 
> When I just pull in the feed’s contents using a NSURLConnection, it will show 
> up on some, but not all, devices.

What does "show up" mean in this case? Is there an error? If so, what is it?

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

UTF-8 is a completely different encoding.

> I validated the feed’s XML and got no errors..

It's valid XML, but it's got some problems as an RSS feed; take a look at

http://feedvalidator.org/check.cgi?url=https%3A%2F%2Fwww.taxpublications.deloitte.co.uk%2Ftis%2Fdtp.nsf%2Fpub1.xml
 

These are mostly minor, like nonstandard extra elements, but it's also got 
problems with its date formatting, and also the server reports the Content-Type 
is ASCII while the XML says it's ISO-8859-1.

If NSXMLParser is having trouble with the encoding, one problem I've seen 
before is documents that claim to be ISO-8859-1 while actually being WinLatin, 
which is a superset with extra characters defined. (The Cocoa encoding name for 
this is NSWindowsCP1252StringEncoding, IIRC.)

(I spent four years of my life immersed in RSS feed parsing, and acquired a 
solid contempt for the ability of the average web developer to construct a 
valid feed. You would not believe how many messed-up feeds there are in the 
real world.)

—Jens
___

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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-23 Thread Keary Suska
On Nov 23, 2014, at 11:06 AM, Diederik Meijer | Ten Horses 
 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: 
> 
> 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

Re: Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-23 Thread Gary L. Wade
First, be sure the content in the XML document you're getting back matches the 
encoding in the header. If it doesn't and you have no control over the creation 
of it, you'll have to figure out the character set yourself. There's also some 
methods in NSString that will try to figure out that for you and return that. 
Secondly, ISO-8859-1 and UTF-8 are not equivalent.
--
Gary L. Wade (Sent from my iPad)
http://www.garywade.com/

> On Nov 23, 2014, at 1:06 PM, Diederik Meijer | Ten Horses 
>  wrote:
> 
> Hi list,
> 
> 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: 
> 
> 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];
> 
> 
> Still, in that case, some devices will show the parsed feed, some won’t.
> 
> I tried converting the data into NSISOLatin1 and then putting it back into 
> NSData using UTF8, as below, but that doesn’t help.
> 
> -(void)connectionDidFinishLoading:(NSURLConnection *)connection {
>NSString *dataString = [[NSString alloc] initWithData:self.dataContainer 
> encoding:NSISOLatin1StringEncoding];
>[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..
> 
> Anybody out there with experience in solving this?
> 
> 
> Many thanks!
> 
> 
> 
> Diederik
> ___
> 
> 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/garywade%40desisoftsystems.com
> 
> This email sent to garyw...@desisoftsystems.com

___

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

Trouble getting ISO-8859-1 encoded feed to parse and display

2014-11-23 Thread Diederik Meijer | Ten Horses
Hi list,

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: 

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];


Still, in that case, some devices will show the parsed feed, some won’t.

I tried converting the data into NSISOLatin1 and then putting it back into 
NSData using UTF8, as below, but that doesn’t help.

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *dataString = [[NSString alloc] initWithData:self.dataContainer 
encoding:NSISOLatin1StringEncoding];
[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..

Anybody out there with experience in solving this?


Many thanks!



Diederik
___

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