I have the following XML:
<Root>
<EventSet>
<Event>
<id>12345</id>
<rant>
<localTime>
<dst>true</dst>
<time>7/2/2012 14:30</time>
</localtime>
<randomRant>
<random>to illustrate point</random>
<rant>help me!</rant>
</randomRant>
</rant>
</Event>
<Event>/*another event*/</Event>
<Event>/*another event*/</Event> //etc
</EventSet>
</Root>
I want to map this to:
[Serializable]
public class Events
{
public List<Event> events { get; set; }
}
[Serializable]
public class Event
{
public int id { get; set; }
public Rant rant { get; set; } //this is where I get confused
}
QUESTION: How do I serialize the tags within <rant>? Do I continue to make serialized classes of the parent until the child tags have no children? For example, below:
[Serializable]
public class Rant
{
public LocalTime localTime { get; set; }
public RandomRant randomRant { get; set; }
}
[Serializable]
public class LocalTime
{
public bool dst { get; set; }
public DateTime time { get; set; }
}
[Serializable]
public class RandomRant
{
public string random { get; set; }
public string rant { get; set; }
}
Or is there a better approach?
EDIT: A given event has one and only one id, and one and only one rant. For the sake of my question, assume my types are valid. I am looking to deserialize nested XML into an object.
DateTimeformats. I want to know how to deserialize into an object from XML with nested tags.