示例#1
0
        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);
        }
示例#2
0
        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());
            }
        }
示例#3
0
        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());
                }
            }
        }