using System.Text;
public static XmlDocument Serialize(Type type, Object source)
{
MemoryStream stream = null;
TextWriter writer = null;
XmlDocument document = null;
try
{
catch (Exception e)
{
finally
{
return document;
}
TextWriter writer = null;
XmlDocument document = null;
try
{
stream = new MemoryStream();
writer = new StreamWriter(stream, Encoding.Unicode);
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, source);
int count = (int)stream.Length;
byte[] array = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(array, 0, count);
UnicodeEncoding utf = new UnicodeEncoding();
document = new XmlDocument();
document.LoadXml(utf.GetString(array).Trim());
}writer = new StreamWriter(stream, Encoding.Unicode);
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, source);
int count = (int)stream.Length;
byte[] array = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(array, 0, count);
UnicodeEncoding utf = new UnicodeEncoding();
document = new XmlDocument();
document.LoadXml(utf.GetString(array).Trim());
catch (Exception e)
{
ExceptionManager.Publish(e);
}finally
{
if (stream != null) stream.Close();
if (writer != null) writer.Close();
}if (writer != null) writer.Close();
return document;

