XML文件序列:SerObj obj = new SerObj();obj.name = "sparon";obj.age = 23;obj.sex = true;XmlSerializer ser = new XmlSerializer(typeof (SerObj));Stream file = new FileStream("test.xml", FileMode.Create, FileAccess.Write);ser.Serialize(file, obj);

解决方案 »

  1.   

    你必须先按XML文档结构写一个类出来才可以deserialize...不过.NET提供了生产代码的工具xsd.exe,自己去查一下用法吧...
      

  2.   

    类已经写好了。问题是deserialize 一个product和deserialize多个product用的是一样的方法吗?因为我的xml文件里有很多productPublic Class Product
    {
       private int code;
       private string name;   public int Code
       {
        ....
       }   public string Name
       {
         ........
       }
    }
      

  3.   

    这个文档结构需要两个类...Products和Product...你直接用xsd.exe生成一个参考吧...
      

  4.   

    这两个类我都会写,只是不知道怎么deserialize这两个类。还有创建这两个类的时候需要加任何attribute吗?