I have the following xml file.
<a>
<b>
<c>val1</c>
<d>val2</d>
</b>
<b>
<c>val3</c>
<d>val4</d>
</b>
<a>
I want to deserialize this into a class and I want to access them with the objects of the class created. I am using C#. I am able to deserialize and get the value into the object of class ‘a
’ (the <a>
tag). but how to access the value of <b>
from this object?
I did the following coding:
[Serializable()] [XmlRoot("a")] public class a { [XmlArray("a")] [XmlArrayItem("b", typeof(b))] public b[] bb{ get; set; } } [Serializable()] public class b { [XmlElement("c")] public string c{ get; set; } [XmlElement("d")] public string d{ get; set; } } class Program { static void Main(string[] args) { a i = null; string path = "test.xml"; XmlSerializer serializer = new XmlSerializer(typeof(a)); StreamReader reader = new StreamReader(path); i = (a)serializer.Deserialize(reader); reader.Close(); //i want to print all b tags here Console.Read(); } }