views:

77

answers:

1

Hi, I tried to read the response data from google weather api, but german umlauts aren't shown correctly. Instead of "ö" I get "^".

I think the problem are those two lines of code:

CXMLElement *resultElement = [nodes objectAtIndex:0];
description = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease];

How can i get data out of resultElement without stringValue?

PS: I use TouchXML to parse xml

+2  A: 

You must be using an NSURLConnection to get your data I suppose. When you receive the data you can convert it to an NSString using appropriate encoding. E.g.

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    if(xmlResponse == nil){
        xmlResponse = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding]; 
    }
    else{
        NSMutableString *temp = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
        [xmlResponse appendString:temp];
        [temp release];
    }

}

Here xmlResponse is the NSMutableString that you can pass to your parser. I have used NSISOLatin1 encoding. You can check other kinds of encoding and see what gives you the characters correctly (NSUTF8StringEncoding should do it I suppose).You can check the API doc for a list of supported encodings.

Hetal Vora