0

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

Claus Broch
  • 9,212
  • 2
  • 29
  • 38
Pascal Bayer
  • 2,615
  • 8
  • 33
  • 51
  • Please post the URL from where you are trying to read the data. – Jim May 27 '10 at 10:10
  • #define GOOGLE_WEATHER_SERVICE @"http://www.google.com/ig/api?weather=%@&hl=de" That's the URL but I've already tested the URL. The xml-response is correct with ö – Pascal Bayer May 27 '10 at 10:53

1 Answers1

2

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
  • 3,341
  • 2
  • 28
  • 53