samsam
samsam

Reputation: 3125

NSString stringWithContentsOfURL encoding Problem

my app downloads and parses an xml file that contains German Umlauts (ä, ö, ü) and other special character (&, % etc). I seem to have a generall lack of understanding when it comes to encoding issues.

so what i do at the moment is:

  1. try to locate if i allready cached the xml file in my apps documents folder

1.a if the file exists i load it into a string

NSString * xmlData = [[NSString alloc] initWithContentsOfFile:filenameStr encoding:NSUTF8StringEncoding error:&error];

1.b if the file doesn't exist download its contents and save it afterwards

NSString *xmlData = [NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:&err];
[xmlData writeToFile: filenameStr atomically: FALSE encoding:NSUTF8StringEncoding error:&error]
  1. afterwards (the data is loaded now) i want to parse it...

however, the contents of the xmlData is already "wrong" after stringWithContentsofURL returns (as i see it in the debugger). Also if i open the file that i saved into my documents folder, it's wrong too.

any advice, links, tips or best practices regarding encoding will be appreciated

thanks

sam

Upvotes: 1

Views: 5583

Answers (2)

Ankit Sachan
Ankit Sachan

Reputation: 7850

the file is not wrong its the encoding issue,

actually when contents are in some other language it is rendered in encoded form.

refer this question for help

xml parsing problem in iPhone

Upvotes: 0

Kai Huppmann
Kai Huppmann

Reputation: 10775

Check the encoding of the xml and use it when initializing the string (see details here)

And because of

I seem to have a generall lack of understanding when it comes to encoding issues.

look here.

Upvotes: 1

Related Questions