I have an XMLDocument that i need to read in and convert into a set of objects. I have the following objects
public class Location
{
public string Name;
public List<Building> Buildings;
}
public class Building
{
public string Name;
public List<Room> Rooms;
}
and i have the following XML file:
<?xml version="1.0" encoding="utf-8" ?>
<info>
<locations>
<location name="New York">
<Building name="Building1">
<Rooms>
<Room name="Room1">
<Capacity>18</Capacity>
</Room>
<Room name="Room2">
<Capacity>6</Capacity>
</Room>
</Rooms>
</Building>
<Building name="Building2">
<Rooms>
<Room name="RoomA">
<Capacity>18</Capacity>
</Room>
</Rooms>
</Building>
</location>
<location name ="London">
<Building name="Building45">
<Rooms>
<Room name="Room5">
<Capacity>6</Capacity>
</Room>
</Building>
</location>
</locations>
</info>
What is the best way of doing this? Should I be serializing the xmldocument to the object automatically or do i need to parse out each element and convert into my object manually? In particular, I am trying to figure out how to convert the collections (locations, buildings, etc).
What is the best suggestion to convert this XML file into basically a
List<Location>
objects?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…