2 notes:
1) c# is case sensitive, which means that
post
is not equal to
Post
2)
List(of comments)
and
List(of posts)
is declared in wrong way
Change its declaration to:
[Serializable, System.Xml.Serialization.XmlRoot("root"), System.Xml.Serialization.XmlType("root")]
public class root
{
[System.Xml.Serialization.XmlArray("posts"), System.Xml.Serialization.XmlArrayItem("post", typeof(Post))]
public List<Post> Posts =new List<Post>();
[System.Xml.Serialization.XmlArray("comments"), System.Xml.Serialization.XmlArrayItem("comment", typeof(Comment))]
public List<Comment> Comments = new List<Comment>();
}
For further information, please see:
XML Serialization and Deserialization: Part-1[
^]
XML Serialization and Deserialization: Part-2[
^]
A Complete Sample of Custom Class Collection Serialization and Deserialization[
^]