views:

23

answers:

1

I was using UTF-8 encoded xml for parsing using NSXMLParser. But some of the special characters were causing problems and so decided to use ISO-8859-15 encoding.

But after that the parser doesnt even start parsing and is giving the error 31 - NSXMLParserUnknownEncodingError. What should I do now? Is it possible by anyway we can parse a ISO-8859-15 encoded xml in iphone? Will libxml or anyother parser provide support for this encoding?

A: 

I solved this issue by myself. We decided to use the UTF-8 encoding for the xml and parsed it using the NSXMLParser. But before the parsing we did the following steps.

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://the url for parsing"]];

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

NSString *result = [[[NSString alloc] initWithData:responseData encoding:NSISOLatin1StringEncoding] autorelease];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[result dataUsingEncoding:NSUTF8StringEncoding]];

Then after that some italian characters(3-4) were still causing problems and we manually replaced them after getting the result.

Now everything works fine.

wolverine