It's a problem with codepages. You're writing into the file in the codepage Windows Western Europe (1252). An XML viewer will always treat a file as having the codepage UTF-8 by default. Needless to say Windows 1252 and UTF-8 encode characters in different ways, so you see garbage. So there are two solutions. Either write the file in Unicode (UTF8 or UTF16) or emit a real XML header which tells the XML viewer that the file is in Windows 1252 (it's the same as ISO-8859-1, which is the name that is standardised). You can do this by using the following header:
Code:
<?xml encoding="ISO-8859-1"?>