using System.Collections.Generic;
using System.Xml.Serialization;
public static void Main(string[] args)
<label name='label-a' text='A' dbpath='module/label-a'/>
<textmemo name='textmemo-a' text='' dbpath='module/textmemo-a'/>
<section name='section-a' text='' dbpath='module/section-a'>
<textmemo name='textmemo-b' text='' dbpath='module/textmemo-b'/>
<section name='section-b' text='' dbpath='module/section-b'>
<textmemo name='textmemo-c' text='' dbpath='module/textmemo-c'/>
<label name='label-c' text='A' dbpath='module/label-c'/>
<section name='section-c' text='' dbpath='module/section-c'>
<label name='label-d' text='A' dbpath='module/label-d'/>
var serializer = new XmlSerializer(typeof(DForm));
var dform = (DForm) serializer.Deserialize(new StringReader(xml));
serializer.Serialize(Console.Out, dform);
public abstract class Widget
public abstract string type { get;}
public string name { get; set; }
public string labelCation { get; set; }
public string text { get; set; }
public string dbpath { get; set; }
public class Textmemo : Widget
public override string type { get; } = "CONTROL";
public class Label : Widget
public override string type { get; } = "LABEL";
public class Section : Widget
public override string type { get; } = "SECTION";
[XmlElement("textmemo", Type=typeof(Textmemo))]
[XmlElement("label", Type=typeof(Label))]
[XmlElement("section", Type=typeof(Section))]
public List<Widget> subsection { get; } = new List<Widget>();
[XmlElement("textmemo", Type=typeof(Textmemo))]
[XmlElement("label", Type=typeof(Label))]
[XmlElement("section", Type=typeof(Section))]
public List<Widget> Widgets { get; } = new List<Widget>();