Question

I load a XML like this:

var url = Application.dataPath + @"/config.xml";
var www = new WWW(url);

while (!www.isDone)
{
    yield return new WaitForSeconds(0.2f);
}

After that I create a XmlTextReader in order to parse that XML:

GameSettings.ParseXML(new XmlTextReader(new StringReader(www.text)));

But I'm having problem with character encoding (é,ç,ã,ê, etc). What can I do make it works?

Was it helpful?

Solution

If you use WWW.text, the function expects the web page contents encoded in UTF-8 or ASCII but your customer uses Windows-1252.

Like Bart already suggested, the best way would be to request that the customer just uses UTF-8. If that is not possible und you are sure that the customer always uses Windows-1252 you can convert the encoding inside your application.

Encoding windows1252 = Encoding.GetEncoding("Windows-1252");
Encoding utf8 = Encoding.UTF8;
byte[] windowsBytes = www.bytes;
byte[] utf8Bytes = Encoding.Convert(windows1252, utf8, windowsBytes);
string converted_xml = utf8.GetString(utf8Bytes);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top