Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Well, there are two aspects here: preserving data and displaying it. XML can certainly handle Unicode, and XmlTextWriter can do so too.

What are you using to display the data though? If this is a Windows Forms application, you may need to explicitly set the font to one which can handle all the Unicode you want. It's definitely worth testing with all the character sets you're interested in (Hebrew etc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top