Reputation: 3125
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.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]
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
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
Upvotes: 0
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