<Root>
    <Channel name="最热">
        <Infos>
            <Info>
                <Title>实习期与试用期什么不同</Title>
                <Url>http://club.cqjob.com/read-htm-tid-31420.html</Url>
                <Date>2011-09-30</Date>
                <Img>
                    <Src>http://club.cqjob.com/images/face/1.gif?1316254800</Src>
                    <Width>120</Width>
                    <Height>120</Height>
                </Img>
            </Info>
            <Info>
                <Title>实习期与试用期什么不同</Title>
                <Url>http://club.cqjob.com/read-htm-tid-31420.html</Url>
                <Date>2011-09-30</Date>
                <Img>
                    <Src>http://club.cqjob.com/images/face/1.gif?1316254800</Src>
                    <Width>120</Width>
                    <Height>120</Height>
                </Img>
            </Info>
            <Info>
                <Title>实习期与试用期什么不同</Title>
                <Url>http://club.cqjob.com/read-htm-tid-31420.html</Url>
                <Date>2011-09-30</Date>
                <Img>
                    <Src>http://club.cqjob.com/images/face/1.gif?1316254800</Src>
                    <Width>120</Width>
                    <Height>120</Height>
                </Img>
            </Info>
        </Infos>
    </Channel>
</Root>
这种结构的的XML如何用反序列化读取,求代码

解决方案 »

  1.   

    高手快来呀,我这里已经有反序列化操作了的类了我现在就是不知道怎么写[XmlRoot("Root")][Serializable]下面该写哪些类
      

  2.   


    举个例子可以不, Channel 类和info类怎么写
      

  3.   

      [XmlRoot("Root")]
        [Serializable]
        public class ClubConfigInternal
        {
            public List<Infos> Channel { get; set; }
        }        [Serializable]
        public class Infos
        {
           //这里怎么写
        }    [Serializable]
        public class Info
        {
           //这里怎么写
        }    [Serializable]
        public class Img
        {
         //这里怎么写
        }
      

  4.   

         public class Info
        {
                   public string title;
                   public string url;
                   public string date;
            public string img;        
        }    public class Infos
        {
            public List<Info> Allinfos = new List<Info>();
        }    [XmlRoot("Channel")]
        public class Channel
        {
            private string name;        [XmlElement("Infos")]
            public List<Infos> children = new List<Infos>();        [XmlAttribute("Name")]
            public string Name
            {
                get { return this.name; }
                set { this.name = value; }
            } }
      

  5.   

    下边是序列化的代码。可以生成看看 Channel root = new Channel();
                root.Name = "最热";
                root.children = new List<Infos>();
                Infos infos = new Infos();
                Info info = new Info();
                info.date = "2011-9-9";
                info.img="hooot:asdfasdfkl";
                info.title="title";
                info.url="url=::::::";
                infos.Allinfos.Add(info);
                root.children.Add(infos);
                //root.children = infos;
                XmlSerializer ser = new XmlSerializer(typeof(Channel));
                FileStream fs = new FileStream(@"d:\aaaa.xml", FileMode.Create, FileAccess.Write);            XmlTextWriter writer = new XmlTextWriter(fs, Encoding.UTF8);
                XmlSerializerNamespaces xmln = new XmlSerializerNamespaces();
                xmln.Add(string.Empty, string.Empty);
                ser.Serialize(writer, root,xmln);
                fs.Close();
      

  6.   

    给你贴个我用的,
       public class TableModel
        {
            private string _engName;            //表的英文名
            private string _chnName;            //表的中文名
            private List<ColumnModel> _columns = new List<ColumnModel>(); //字段结构
        }
      public class ColumnModel
        {
            private string _engName;            //表中字段名
            private string _chnName;
            private bool _isPrimary;
            private FieldType _fieldType;
            private bool _callstoredprocedure;
        }
    所有这些要封装的,还有构造函数,我这里都省略了。
    xml<?xml version="1.0" encoding="utf-8"?>
    <TableModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <EngName>model</EngName>
      <ChnName>订单处理后表格</ChnName>
      <Columns>
        <ColumnModel>
          <EngName>Material_Package_Number</EngName>
          <ChnName>号码</ChnName>
          <IsPrimary>false</IsPrimary>
          <FieldType>CHAR</FieldType>
      <Callstoredprocedure>false</Callstoredprocedure>
          <Unique>false</Unique>
      <Visible>true</Visible>
        </ColumnModel>
    <ColumnModel>
          <EngName>line</EngName>
          <ChnName>产线</ChnName>
          <IsPrimary>false</IsPrimary>
          <FieldType>CHAR</FieldType>
      <Callstoredprocedure>false</Callstoredprocedure>
          <Unique>false</Unique>
      <Visible>true</Visible>
        </ColumnModel>
     </Columns>
    </TableModel>将就着看看吧
    xml跟类里面要一一对应,可以用来list来描述字段结构
      

  7.   

    6楼那位大哥已经写得很清楚了只要再把Img的依葫芦画瓢写写就完了