This is my input XML file:
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<host>
<hostId>239|BS|OWN</hostId>
<images>
<image>
<name>Pic.jpg</name>
<main>true</main>
<source>../Images/Melissa/Pic.jpg</source>
</image>
</images>
</host>
</hosts>
and this is my class used to deserialiaze that XML file:
[XmlRoot("hosts")]
public class hosts
{
[XmlElement("host")]
public List<Host> Listehosts { get; set; }
}
public class Host
{
[XmlElement("hostId")]
public string hostId { get; set; }
[XmlElement("images")]
public List<Image> Listeimages { get; set; }
}
public class Image
{
[XmlElement("name")]
public string name { get; set; }
[XmlElement("main")]
public string main { get; set; }
[XmlElement("source")]
public string source { get; set; }
}
And this the code of my main program:
string outputTmp = "Images.xml";
XmlSerializer deserializer = new XmlSerializer(typeof(hosts));
TextReader reader = new StreamReader(outputTmp);
object obj = deserializer.Deserialize(reader);
hosts XmlData = (hosts)obj;
reader.Close();
Console.WriteLine(XmlData.Listehosts.Count);
The problem is that always images list are empty when I execute my program.
The list of hosts is charged correctly but when I checked the list of image it contains permanently null value for all the attribute (name, main, source).
Am I missing something?