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;
            }
        }
    }

你可能感兴趣的:(document)