Serialize Object to string
public static string Serialize(object o, Type T)
{
//this avoids xml document declaration
XmlWriterSettings settings = new XmlWriterSettings()
{
Indent = false,
OmitXmlDeclaration = true
};
var stream = new MemoryStream();
using (XmlWriter xw = XmlWriter.Create(stream, settings))
{
//this avoids xml namespace declaration
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(
new[] { XmlQualifiedName.Empty });
XmlSerializer x = new XmlSerializer(T, "");
x.Serialize(xw, o, ns);
}
return Encoding.UTF8.GetString(stream.ToArray());
}