Fork me on GitHub
XmlDocument序列化到Session
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace Hxh.API
{
 /// <summary>
 /// Serializer 的摘要说明。
 /// </summary>
 public class Serializer
 {
  public Serializer()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  }

  public static object Serialize(object doc)
  {
   MemoryStream ms=new MemoryStream();
   XmlSerializer xs=new XmlSerializer(typeof(XmlDocument));
   xs.Serialize(ms,doc);
   return ms;
  }

  public static object Deserialize(object ms)
  {
   try
   {
    XmlSerializer xs = new XmlSerializer(typeof(XmlDocument));
    MemoryStream msop=(MemoryStream)ms;
    msop.Seek(0,SeekOrigin.Begin);
    return xs.Deserialize(msop);
   }
   catch(Exception ex)
   {
    Console.WriteLine(ex.ToString());
    return null;

   }
  }
 }
}

posted on 2010-04-30 15:16  HackerVirus  阅读(416)  评论(0编辑  收藏  举报