I’m reading an XML file from a REST web service, parsing it, and displaying the details in a UITableView. The XML file is in encoded as iso-8859-1 and contains accented characters. If I just add the string to the tableview then I get a junk character displayed, so I’ve tried to convert it to UTF8 but it gets converted to a question mark, implying it doesn’t understand the character.
Here’s the code:
foreach(XmlNode myNode in myNodeList)
{
Encoding isoEnc = Encoding.GetEncoding ("iso-8859-1");
string utfResult = Encoding.UTF8.GetString (isoEnc.GetBytes(myNode.InnerText));
_myCollection.Add(utfResult);
}
Any ideas what’s going on here, and how to display the accented chars?
OK, problem now solved. It seems that my error was assuming that the StreamReader would deal with the iso-8859-1 encoding by default. I changed my StreamReader constructor from:
to:
By telling the StreamReader to expect the correct encoding, everything else just falls into place.