So far I have the following PCO
[XmlRoot("stat"), Serializable]
public class AkamaiDirectoryStructure
{
[XmlAttribute("directory")]
public string DirectoryName { get; set; }
[XmlElement("file")]
public AkamaiFileStructure Files { get; set; }
}
public class AkamaiFileStructure
{
[XmlAttribute("type")]
public string Type { get; set; }
[XmlAttribute("name")]
public string Name { get; set; }
[XmlAttribute("mtime")]
public long MTime { get; set; }
[XmlAttribute("target")]
public string Target { get; set; }
[XmlAttribute("size")]
public long Size { get; set; }
[XmlAttribute("md5")]
public string MD5 { get; set; }
}
My Xml looks like this
<stat directory="/dir1/dir2">
<file type="file" name="file.html" mtime="1260000000" size="1234567"
md5="0123456789abcdef0123456789abcdef" />
<file type="dir" name="dir3" mtime="1260000000" />
</stat>
What I would like to achieve is a structure smart enough to serialize the different types of file nodes into different objects so
[XmlRoot("stat"), Serializable]
public class AkamaiDirectoryStructure
{
[XmlAttribute("directory")]
public string DirectoryName { get; set; }
[XmlElement("file")] // where type = file
public AkamaiFileStructure Files { get; set; }
[XmlElement("file")] // where type = dir
public AkamaiSubDirectoryStructure SubDirectories { get; set; }
...
}
So can I direct an element to a populate a different object based on an attribute? I know I can do it with the xsi:type