Look at your code.
new XmlRootAttribute("form-template")
mapped to <form-template>
node.
public class Field
mapped to <field
node.
But nothing is displayed on <fields>
node.
Add the following class:
public class FieldList
{
[XmlArray("fields")]
[XmlArrayItem("field")]
public List<Field> Fields { get; set; }
}
It should work:
var serializer = new XmlSerializer(typeof(FieldList), new XmlRootAttribute("form-template"));
var stringReader = new StringReader(xml);
var xmlFields = (FieldList)serializer.Deserialize(stringReader);
, Option
:
[XmlText]
public string Text { get; set; }
Update.
FieldList
. xml.
List<Field> xmlFields;
var serializer = new XmlSerializer(typeof(List<Field>), new XmlRootAttribute("fields"));
using (var xmlReader = XmlReader.Create("test.xml"))
{
xmlReader.ReadToFollowing("fields");
xmlFields = (List<Field>)serializer.Deserialize(xmlReader);
}
XmlType
:
[XmlType("field")]
public class Field