views:

247

answers:

2

Hi,

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?

+2  A: 

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

CptSkippy
Do you mean that my program currently allows all languages?
Bab Yogoo
Yes! http://en.wikipedia.org/wiki/UTF-8#Advantages_3
CptSkippy
+1  A: 

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).

Jon Skeet
I'm using WPF and standard text-boxes. Will I have a problem?
Bab Yogoo
No, WPF should handle automatic font substitution for when the standard font lacks characters for a particular script. So you should be fine.
Pavel Minaev
I'd still test just to make sure though :)
Jon Skeet