On Jun 26, 3:49 pm, "Phil Hunt" <a...@aaa.comwrote:
Quote:
The following is what I have :
>
XmlWriterSettings xmlSettings = new XmlWriterSettings();
xmlSettings.Indent = true;
xmlSettings.IndentChars = " ";
xmlSettings.Encoding = System.Text.Encoding.UTF8;
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb, xmlSettings))
>
============
The problem I have is the xml comes out with
<?xml Version="1.0" encoding="utf-16"?>
>
It really does not matter what I have in the xmlSettings, it always comes
out utf-16.
>
???? What am i missing ?????
|
You need a StringWriterWithEncoding, rather than passing in a
StringBuilder directly.
The StringWriterWithEncoding code is really simple though:
public class StringWriterWithEncoding : StringWriter
{
Encoding encoding;
public StringWriterWithEncoding (Encoding encoding)
{
this.encoding = encoding;
}
public override Encoding Encoding
{
get { return encoding; }
}
}
You could add other constructor overloads should you wish, of course.
Jon