views:

496

answers:

3

Hello,

I have this xml feed in Chinese, which NSXLParsers is unable to parse. It gives error 31 while parsing.

error 31 occur due to Document encoding is unknown.

I tried UTF-8 and ascii encodings to convert string rendered via

[NSString stringwithContentsOfURL:@"http://news.baidu.com/n?cmd=4&class=finannews&tn=rss"]

to corresponding format.

Can any body shed some light on how to parse XML feeds written in another languages.

Thanx in advance

+1  A: 

The answer is the first line of the feed

<?xml version="1.0" encoding="gb2312"?>

Then read about gb2312

sylvanaar
+1  A: 

Since the file is encoded in GB2312, you should provide an encoding with

[NSString stringWithContentsOfURL:@"http://..."
                         encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_2312_80)
                            error:NULL];
KennyTM
cocoa error 261 occured. This error occured due to Read error because the string encoding was not applicable.
Ankit Sachan
It could probably be `kCFStringEncodingGB_18030_2000` or `kCFStringEncodingGBK_95`.
KennyTM
A: 

Try to debugg using

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]];
    NSLog(@"error parsing XML: %@", errorString);

    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

It will help to find whether the problem is with the xml or the encoding method

Nithin