Consider the code below
XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
using (TextWriter writer = new StreamWriter(fileName))
{
// Serialize the object, and close the TextWriter.
serializer.Serialize(writer, invoice);
writer.Close();
}
No encoding is set on the stream writer by default. Does it default to UTF-8 if you don't set an encoding on the stream writer?
Unicode Transformation Format, 8-bit encoding form is designed for ease of use with existing ASCII-based systems and enables use of all the characters in the Unicode standard.
xml version="1.0" encoding="ISO-8859-1"?> Without this information, the default encoding is UTF-8 or UTF-16, depending on the presence of a UNICODE byte-order mark (BOM) at the beginning of the XML file.
It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The World Wide Web Consortium's XML 1.0 Specification of 1998 and several other related specifications—all of them free open standards—define XML. XML (standard) Extensible Markup Language. Abbreviation.
Yes, by default StreamWriter
is created for using UTF-8 without preamble. See details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With