Getting "" at the beginning of my XML File after save() [duplicate]
It is the UTF-8 BOM, which is actually discouraged by the Unicode standard:
http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf
Use of a BOM is neither required nor recommended for UTF-8, but may be encountered in contexts where UTF-8 data is converted from other encoding forms that use a BOM or where the BOM is used as a UTF-8 signature
You may disable it using:
var sw = new IO.StreamWriter(path, new System.Text.UTF8Encoding(false));doc.Save(sw);sw.Close();
You can try to change the encoding of the XmlDocument. Below is the example copied from MSDN
using System; using System.IO; using System.Xml;public class Sample { public static void Main() { // Create and load the XML document. XmlDocument doc = new XmlDocument(); string xmlString = "<book><title>Oberon's Legacy</title></book>"; doc.Load(new StringReader(xmlString)); // Create an XML declaration. XmlDeclaration xmldecl; xmldecl = doc.CreateXmlDeclaration("1.0",null,null); xmldecl.Encoding="UTF-16"; xmldecl.Standalone="yes"; // Add the new node to the document. XmlElement root = doc.DocumentElement; doc.InsertBefore(xmldecl, root); // Display the modified XML document Console.WriteLine(doc.OuterXml); }
}