Search code examples
c#xmlxmltextwriterwriteelementstring

XmlTextWriter: Allows Unicode?


I'm using XmlTextWriter to save certain configuration elements for my program (it's only 10-15 string values, this is why I'm using XmlTextWriter). My code looks as follows:

XmlTextWriter writer = new XmlTextWriter("FILENAME.XML", null);

writer.WriteStartElement("Config");
writer.WriteElementString("Param1", param1);
writer.WriteElementString("Param2", param2);
...
writer.WriteEndElement();

writer.Close();

I would like to allow the paramX values to contain unicode. Not anything too fancy - these values comes from text-boxes the user inputs data into, and I want the system to work fine globally (Chinese, Japanese, Hebrew, Arabic, etc). I'm not parsing the data, I just want to it be presented well the next time the program loads.

What's the way to achieve this?


Solution

  • The second parameter of the constructor is the encoding. The default encoding if left null is UTF8.