Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8" ?>
- <PropertyInformation>
- <locations>
- <location name="Bombay">
- <Buildings>
- <Building name="Majestic House">
- <Rooms>
- <Room name="Delmonte Conference Room">
- <Capacity>325</Capacity>
- </Room>
- <Room name="Majestic Ballroom">
- <Capacity>150</Capacity>
- </Room>
- </Rooms>
- </Building>
- <Building name="Taj Mahal Palace Hotel">
- <Rooms>
- <Room name="THE LUXURY GRANDE">
- <Capacity>4</Capacity>
- </Room>
- </Rooms>
- </Building>
- </Buildings>
- </location>
- <location name="New York">
- <Buildings>
- <Building name="City Group Center">
- <Rooms>
- <Room name="LeMessurier Hall">
- <Capacity>210</Capacity>
- </Room>
- </Rooms>
- </Building>
- </Buildings>
- </location>
- </locations>
- </PropertyInformation>
Expand|Select|Wrap|Line Numbers
- public class Room
- {
- [XmlAttribute("name")]
- public String Name { get; set; }
- public int Capacity { get; set; }
- }
- public class Building
- {
- [XmlAttribute("name")]
- public String Name { get; set; }
- public List<Room> Rooms { get; set; }
- }
- public class Location
- {
- [XmlAttribute("name")]
- public string Name { get; set; }
- public Building Buildings { get; set; }
- }
- [XmlRoot("PropertyInformation")]
- public class PropertyInformation
- {
- [XmlArray("locations")]
- [XmlArrayItem("location")]
- public List<Location> Locations { get; set; }
- }
- I created following DAL class to load the information from PropertyInfo.xml :-
- public class PropertyInfoDal
- {
- public List<Location> LoadPropertyInfo()
- {
- DataSet ds = new DataSet();
- XmlSerializer xmlSerializer = new XmlSerializer(typeof(DataSet));
- FileStream readStream = new FileStream("~/App_Data/PropertyInfo.xml", FileMode.Open);
- ds = (DataSet) xmlSerializer.Deserialize(readStream);
- readStream.Close();
- //How to Cast DataSet to Strongly Typed Object( List<Location>) before it gets returned ??
- //I started with this much below
- List<Location> locations = (from row in ds.Tables[0].AsEnumerable()
- select new PropertyLocation
- {
- Name = row.Field<String>("Name"),
- Buildings = ?????
- }).ToList();
- return locations;
- }
- }