以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML工具及XML开发环境 』  (http://bbs.xml.org.cn/list.asp?boardid=7)
----  类的系列化问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=7&rootid=&id=18967)


--  作者:l1419
--  发布时间:5/29/2005 9:11:00 PM

--  类的系列化问题
怎样写一个类,在类的属性上加上特性,让它在被系列化时可以被系列化成:
  <DropDownList ID="" align="Center" bgColor="#00ff99" ReadOnly="F" num="3">
          <Selection Key="女">女Selection>
          <Selection Key="男"> 男 </Selection>
          <Selection Key="男"> 男 </Selection>
   </DropDownList>

我的类是这样写的,但是系列化结果不符以上要求

public class DropDownList
 {  
  [XmlElement(typeof(Selection), ElementName = "Selection")]
  
  public ArrayList selections = new ArrayList();
  
  public DropDownList()
  {
   //
   // TODO: Add constructor logic here
   //
  }

  [XmlAttribute]
  public string  ID ="";
  private string _title;
  
  [XmlAttribute]
  public  string  Title
  {
  
   set
   {
    _title = value;
    ToolTip = value;
   }
   get
   {
    return _title;
   }
  }

  [XmlAttribute]
  public string  align ="Center";

  [XmlAttribute]
  public string  bgColor = "#00ff99";

  [XmlAttribute]
  public string  ToolTip;

  [XmlAttribute]
  public string  ReadOnly = "F";
       
  [XmlAttribute]
  public string num;

 }

  selection类是这样写的
   public class Selection
 {
  public Selection()
  {
   //
   // TODO: 在此处添加构造函数逻辑
   //
  
  }
      
  
  [XmlAttribute]
  public string Key;

  public string content;
  
 }

把selection逐个添加到dropdownlist的selection中,系列化dropdownlist后结果是:
   <DropDownList ID="" align="Center" bgColor="#00ff99" ReadOnly="F" num="3">
          <Selection Key="女">
            <content>女</content>
          </Selection>
          <Selection Key="男">
            <content>男</content>
          </Selection>
        </DropDownList>

改怎样改正?各位大虾,希望不吝赐教。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
35.156ms