///
/// 序列化成XML
///
///
///
///
public static string XmlSerialize(T obj, Encoding encoding)
{
string result = string.Empty;
try
{
using (MemoryStream memoryStream = new MemoryStream())
{
XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
//序列化对象
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "");
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
xmlTextWriter.Formatting = System.Xml.Formatting.None;
xmlSerializer.Serialize(xmlTextWriter, obj, namespaces);
xmlTextWriter.Flush();
xmlTextWriter.Close();
result = encoding.GetString(memoryStream.ToArray());
}
}
catch
{
}
return result;
}