private void SaveFile(FileData file) { // by default .NET reformats the whole XML. These settings produce almost same format as the TV xml files use var xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = new UTF8Encoding(false); xmlSettings.CheckCharacters = false; xmlSettings.Indent = true; xmlSettings.IndentChars = file.indent; xmlSettings.NewLineHandling = NewLineHandling.None; xmlSettings.NewLineChars = file.newline; xmlSettings.OmitXmlDeclaration = false; string xml; using (var sw = new StringWriter()) using (var w = new CustomXmlWriter(sw, xmlSettings, false)) { file.doc.WriteTo(w); w.Flush(); xml = sw.ToString(); } var enc = new UTF8Encoding(false, false); File.WriteAllText(file.path, xml, enc); }
private void SaveFile(FileData file) { // by default .NET reformats the whole XML. These settings produce almost same format as the TV xml files use var xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = new UTF8Encoding(false); xmlSettings.CheckCharacters = false; xmlSettings.Indent = true; xmlSettings.IndentChars = file.indent; xmlSettings.NewLineHandling = NewLineHandling.None; xmlSettings.NewLineChars = file.newline; xmlSettings.OmitXmlDeclaration = true; string xml; using (var sw = new StringWriter()) { // write unmodified XML declaration (the DVB*.xml files use a different one than the Favorite.xml file) var i = file.textContent.IndexOf("?>"); if (i >= 0) { sw.Write(file.textContent.Substring(0, i + 2 + file.newline.Length)); } using (var w = new CustomXmlWriter(sw, xmlSettings, false)) { file.doc.WriteTo(w); w.Flush(); xml = sw.ToString(); } } // append trailing newline, if the original file had one if (file.textContent.EndsWith(file.newline) && !xml.EndsWith(file.newline)) { xml += file.newline; } var enc = new UTF8Encoding(false, false); File.WriteAllText(file.path, xml, enc); }