Пример #1
0
        public static string ObjectToXML(object input, bool isWss40, XmlAttributeOverrides xmlOverrides)
        {
            string resultXml = null;

            XmlSerializer serializer = GetXmlSerializer(input.GetType(), xmlOverrides);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                SPXmlTextWriter writer = new SPXmlTextWriter(memoryStream, null);
                writer.IsWss40 = isWss40;

                //XmlTextWriter writer = new XmlTextWriter(memoryStream, null);

                //writer.NewlineTags = NewlineTags;
                writer.Formatting = Formatting.Indented;

                XmlSerializerNamespaces namespaceSerializer = new XmlSerializerNamespaces();
                namespaceSerializer.Add("", "http://schemas.microsoft.com/sharepoint/");

                // Do the serialization here!
                serializer.Serialize(writer, input, namespaceSerializer);

                resultXml = Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            return(resultXml);
        }
Пример #2
0
        public static string FormatXml(string xml)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xml);
            string result = string.Empty;

            using (StringWriter sw = new StringWriter())
            {
                //XmlTextWriter xtw = new XmlTextWriter(sw);
                SPXmlTextWriter writer = new SPXmlTextWriter(sw);
                writer.NewlineTags = NewlineTags;
                writer.Formatting  = Formatting.Indented;

                xDoc.WriteTo(writer);
                result = sw.ToString();
            }

            return(result);
        }