I'm trying to deserialize one xml document to c# class
I followed that tuto but It doesn't work in my case : https://stackoverflow.com/a/364401/10824921
But my listPersons remain empty
There is XML :
<?xml version="1.0" encoding="utf-8"?>
<PersonList>
<Person id="0" tag="ASD">
<Name>Smith</Name>
</Person>
<Person id="1" tag="FDS">
<Name>Johny</Name>
</Person>
</PersonList>
There is C# code :
[Serializable()]
[XmlRoot("PersonList")]
public class PersonList
{
[XmlArrayItem("Person", typeof(Person))]
public Person[] Person { get; set; }
}
[Serializable()]
public class Person
{
[XmlAttribute("id")]
public int ID { get; set; }
[XmlAttribute("tag")]
public string Tag{ get; set; }
[XmlElement("Name")]
public string Name{get; set;}
}
class Program
{
static void Main(string[] args)
{
PersonList listPersons = null;
string path = "personlist.xml";
XmlSerializer serializer = new XmlSerializer(typeof(PersonList ));
StreamReader reader = new StreamReader(path);
listPersons= (PersonList)serializer.Deserialize(reader);
reader.Close();
}
}