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

<p>so what i do at the moment is:</p>

<ol>
<li>try to locate if i allready cached the xml file in my apps documents folder</li>
</ol>

<p>1.a if the file exists i load it into a string </p>

<pre><code>NSString * xmlData = [[NSString alloc] initWithContentsOfFile:filenameStr encoding:NSUTF8StringEncoding error:&amp;error];
</code></pre>

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

<pre><code>NSString *xmlData = [NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:&amp;err];
[xmlData writeToFile: filenameStr atomically: FALSE encoding:NSUTF8StringEncoding error:&amp;error]
</code></pre>

<ol>
<li>afterwards (the data is loaded now) i want to parse it...</li>
</ol>

<p>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.</p>

<p>any advice, links, tips or best practices regarding encoding will be appreciated</p>

<p>thanks</p>

<p>sam</p>
