The encoding written into the XML document and the actual encoding of the XML data are determined by the Writer passed into the
Serialize method of
LxSerializer.
For example, if a .Net XmlWriter is used, then you can specify the encoding using XmlWriterSettings:
MyElementClass elmCls = ...;
XmlWriterSettings xws = new XmlWriterSettings() { Encoding = Encoding.Unicode };
using (XmlWriter writer = XmlWriter.Create("MyXmlFile.xml", xws))
{
serializer.Serialize(writer, elmCls);
}
Whereas, if a StreamWriter is used, the encoding can be set on the constructor:
MyElementClass elmCls = ...;
using (StreamWriter sw = new StreamWriter("MyXmlFile.xml", Encoding.Unicode))
{
serializer.Serialize(writer, elmCls);
}
Note: If a StringWriter is used, the output will always be UTF-16 as this is how .Net stores strings internally.
Article ID: 145, Created: 6/10/2020 at 8:55 AM, Modified: 6/10/2020 at 8:57 AM