Consider the following XML:
<?xml version="1.0" encoding="utf-8"?>
<treelist id="foo" displayname="display">
<treelink id="link" />
</treelist>
I've got the following code set up:
private static void Main(string[] args)
{
StreamReader result = File.OpenText(@"test.xml");
var xmlTextReader = new XmlTextReader(result.BaseStream, XmlNodeType.Document, null);
XDocument load = XDocument.Load(xmlTextReader);
var xmlSerializer = new XmlSerializer(typeof (TreeList));
var foo = (TreeList) xmlSerializer.Deserialize(load.CreateReader());
}
And these are my entities:
[Serializable]
[XmlRoot("treelink")]
public class TreeLink
{
[XmlAttribute("id")]
public string Id { get; set; }
}
[Serializable]
[XmlRoot("treelist")]
public class TreeList
{
[XmlAttribute("id")]
public string Id { get; set; }
[XmlAttribute("displayname")]
public string DisplayName { get; set; }
[XmlArray("treelist")]
[XmlArrayItem("treelist", typeof (TreeLink))]
public TreeLink[] TreeLinks { get; set; }
}
However I am not able to deserialize the treelink objects, in foo
the TreeLinks always stays null.
What am I doing wrong here?