Martijn Burger
Martijn Burger

Reputation: 7543

Change character encoding on a XML Fragment in C#

I have written the following to read an XML fragement from disk:

string fileName = @"C:\test.txt";
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
using (XmlReader reader = XmlReader.Create(fileName, settings))
{
    while (reader.Read())
    { DoSomething(); }
}

But it fails when reading special characters like Ö, &, etc. I guess this is something with character encoding. I saw that I can do something like XmlReader.Create(fileName, fileEndoding). However, how do I combine this with the setting of a XMLFragment? My character encoding is ISO8859-1

Upvotes: 0

Views: 307

Answers (1)

VAV
VAV

Reputation: 1896

Try this: new StreamReader(fileName, Encoding.GetEncoding("ISO-8859-1"))

Upvotes: 1

Related Questions