public string GetXml() { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, IndentChars = "\t", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace, ConformanceLevel = ConformanceLevel.Document }; string result; using (StringWriter sw = new CustomEncodingStringWriter(Encoding.UTF8)) { using (var xw = XmlWriter.Create(sw, settings)) { _xDocument.Save(xw); } result = sw.ToString(); } return(result); }
public static async Task <string> XmbToXmlAsync(byte[] data) { using (var fileStream = new MemoryStream(data, false)) { XMBFile xmb = await XMBFile.LoadXMBFile(fileStream); using StringWriter sw = new CustomEncodingStringWriter(Encoding.UTF8); using XmlTextWriter textWriter = new XmlTextWriter(sw); textWriter.Formatting = Formatting.Indented; xmb.file.Save(textWriter); return(sw.ToString()); } }
public string Serialize(object obj, bool omitHeaderDeclaration = false) { var serializer = new XmlSerializer(obj.GetType()); var namespaces = new XmlSerializerNamespaces(); namespaces.Add("wps", ModelNamespaces.Wps); namespaces.Add("ows", ModelNamespaces.Ows); namespaces.Add("xli", ModelNamespaces.Xlink); namespaces.Add("xsi", ModelNamespaces.XmlSchemaInstance); var settings = new XmlWriterSettings { OmitXmlDeclaration = omitHeaderDeclaration }; using (var writer = new CustomEncodingStringWriter(Encoding.UTF8)) { using (var xmlWriter = XmlWriter.Create(writer, settings)) { serializer.Serialize(xmlWriter, obj, namespaces); return(writer.ToString()); } } }