Geeks With Blogs
.Nettuce Code Salad
        public static string ToXml<T>(this T obj) where T : class
        {
            using (var stringWriter = new StringWriter())
            {
                var xmlWriterSettings = new XmlWriterSettings { OmitXmlDeclaration = true };
                using (var xmlWriter = XmlWriter.Create(stringWriter, xmlWriterSettings))
                {
                    var xmlSerializerNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
                    var xmlSerializer = new XmlSerializer(typeof(T));
                    xmlSerializer.Serialize(xmlWriter, obj, xmlSerializerNamespaces);
                }
                return stringWriter.ToString();
            }
        }
Posted on Tuesday, June 12, 2012 4:40 PM | Back to top


Comments on this post: Serialize plain clean XML in .NET

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net