XmlDocument序列化到Session[转]

 public class Serializer
    {
        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)
            {
                return null;
            }
        }
    }

posted @ 2010-05-24 17:13  smodi  阅读(213)  评论(0编辑  收藏  举报