1,建立xsd
step1:建立“类型”Version、Updatetime,Files,File
step2:建立Files与File的多对一关系,添加Files中的file引用(是File类型的),修改file的属性maxOccurs为unbounded,minOccurs为1
如图:
step3:建立顶级元素“类型”Update,添加version,updatetime,files的引用,如图
step4:添加顶级元素update(类型为Update),如图

xsd代码如下:
<? xml version ="1.0" encoding ="utf-8" ?>
< xs:schema id ="UpdateFile" targetNamespace ="http://tempuri.org/UpdateFile.xsd" elementFormDefault ="qualified" xmlns ="http://tempuri.org/UpdateFile.xsd" xmlns:mstns ="http://tempuri.org/UpdateFile.xsd" xmlns:xs ="http://www.w3.org/2001/XMLSchema" >
     < xs:complexType name ="Update" >
         < xs:sequence >
             < xs:element name ="version" type ="Version" />
             < xs:element name ="updatetime" type ="Updatetime" />
             < xs:element name ="files" type ="Files" />
         </ xs:sequence >
     </ xs:complexType >
     < xs:complexType name ="Version" >
         < xs:sequence >
             < xs:element name ="value" type ="xs:string" />
             < xs:element name ="type" type ="xs:string" />
         </ xs:sequence >
     </ xs:complexType >
     < xs:complexType name ="Updatetime" >
         < xs:sequence >
             < xs:element name ="value" type ="xs:dateTime" />
         </ xs:sequence >
     </ xs:complexType >
     < xs:complexType name ="Files" >
         < xs:sequence >
             < xs:element name ="file" type ="File" maxOccurs ="unbounded" minOccurs ="1" />
         </ xs:sequence >
     </ xs:complexType >
     < xs:complexType name ="File" >
         < xs:sequence >
             < xs:element name ="url" type ="xs:string" />
         </ xs:sequence >
     </ xs:complexType >
     < xs:element name ="update" type ="Update" >
     </ xs:element >
</ xs:schema >

2,生成实体类
用vs命令行在项目文件夹下输入以下命令
xsd.exe 要生成实体类的.xsd /c /namespace:要生成的实体类的命名空间


3,两个静态工具类
InBlock.gif class Common
InBlock.gif        {
InBlock.gif                 /// <summary>
InBlock.gif                 /// 将XML文件写入指定的对象
InBlock.gif                 /// </summary>
InBlock.gif                 /// <param name="xmlFile">xml绝对路径</param>
InBlock.gif                 /// <param name="type">序列的类型,要与XML对应的类</param>
InBlock.gif                 /// <returns>将对象返回,当文件操作失败则返回Null值</returns>
InBlock.gif                 public static object DeserializeXmlToObject( string xmlFile, Type type)
InBlock.gif                {
InBlock.gif                        XmlSerializer mySerializer = new XmlSerializer(type);
InBlock.gif                         using (FileStream stream = new FileStream(xmlFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
InBlock.gif                        {
InBlock.gif                                 return mySerializer.Deserialize(stream);
InBlock.gif                        }
InBlock.gif                }
InBlock.gif
                 /// <summary>
InBlock.gif                 ///    将对象写入到XML中
InBlock.gif                 /// </summary>
InBlock.gif                 /// <param name="obj">数据源对象</param>
InBlock.gif                 /// <param name="xmlFile">目标路径</param>
InBlock.gif                 /// <param name="type">转换类型</param>
InBlock.gif                 public static void SerializeObjectToXml( object obj, String xmlFile, Type type)
InBlock.gif                {
InBlock.gif                        XmlSerializer mySerializer = new XmlSerializer(type);
InBlock.gif                         using (FileStream stream = new FileStream(xmlFile, FileMode.Create, FileAccess.Write, FileShare.Read))
InBlock.gif                        {
InBlock.gif                                mySerializer.Serialize(stream, obj);
InBlock.gif                        }
InBlock.gif                }
InBlock.gif        }

4,序列化与反序列化
InBlock.gif //反序列化
InBlock.gif                                Update a = new Update();
InBlock.gif                                a.version = new Version();
InBlock.gif                                a.version.type = "0";
InBlock.gif                                a.version.value = "1.0.0.0";
InBlock.gif                                a.updatetime = new Updatetime();
InBlock.gif                                a.updatetime.value = new System.DateTime();
InBlock.gif                                a.files = new File[1];
InBlock.gif                                a.files[0] = new File();
InBlock.gif                                a.files[0].url = "http://test.exe";
InBlock.gif                                Common.SerializeObjectToXml(a, "目标.xml", typeof(Update));
InBlock.gif
                                //系列化
InBlock.gif                                Update u = (Update)Common.DeserializeXmlToObject("目标.xml", typeof(Update));

5,gameover