Knowledge Management Banner

Knowledge Management Banner

Object to xml string

//Required Libraries
using System.Xml.Serialization;
using System.IO;

public static string ObjectToXMLString(object T)
{
    string xmlData = string.Empty;
    var SR = new XmlSerializer(T.GetType());

    using (var stringwriter = new StringWriter())
    {
        SR.Serialize(stringwriter, T);

        xmlData = stringwriter.ToString();

        return xmlData;
    }
}

No comments

Powered by Blogger.