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;



   }

  }

 }

}



你可能感兴趣的:(document)