[Serializable]    
public abstract a
{
     private string _name = string.empty;
    [XmlAttribute()]
     public string Name
      {
           get{ return _name;}
           set{ _name = value;}
      }
}
[Serializable]
 public class AA:a
{
    .......
}
 [Serializable]
   public class BB :a
{
      ........
}
[Serializable]
 public class XX
{
     private  List<a> _children = new List<a>();
     [System.Xml.Serialization.XmlArray("as")]
     [System.Xml.Serialization.XmlArrayItem("AA", typeof(AA)),
        System.Xml.Serialization.XmlArrayItem("BB", typeof(BB))]
     public List<a> Children
    {
           get{ return _children;}
           set{_children = value;}
    }
}

 public Main()
{
       XX x = new  XX();
       x.Children.add( new AA());
       x.Children.add( new BB());
       XmlSerializer s = new  XmlSerializer( x.gettype() );
       using ( stringWrite w = new stringwriter() )
     {
            w.Serialize( w ,  xx.gettype()  );
     }
 }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2021-06-26
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2022-01-20
  • 2022-01-10
  • 2021-06-09
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案