NSString to NSData Failing in Encoding

Posted by Travis on Stack Overflow See other posts from Stack Overflow or by Travis
Published on 2010-03-21T04:24:25Z Indexed on 2010/03/21 4:31 UTC
Read the original article Hit count: 472

I'm trying to use NSXmlParser to parse ISO-8859-1 data. Using Apple's own example for parsing ISO-8859-1, I have the following.

NSString *xmlFilePath = [[NSBundle mainBundle] pathForResource:sampleFileName ofType:@"xml"];

NSString *xmlFileContents = [NSString stringWithContentsOfFile:xmlFilePath encoding:NSISOLatin1StringEncoding error:nil];

NSLog(@"contents: %@", xmlFileContents);

I see that in the console, the contents of the string is accurate.

However when I try to convert it to an NSData object (for use with the parser), I do the following.

NSData *xmlData = [xmlFileContents dataUsingEncoding:NSISOLatin1StringEncoding]; 

But then when my didStartElement delegate gets called, I see  showing up which I think is from an encoding discrepancy.

Can NSXmlParser handle ISO-8859-1 and if so, what am I doing wrong?

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about nsxmlparser