Performing the example of this thread I find an error when deserializar the object location and room:
static void Main(string[] args)
{
Location locations = new Location();
Room rooms = new Room();
XmlReaderSettings settings = new XmlReaderSettings
{
ConformanceLevel = ConformanceLevel.Fragment
};
using (var reader = XmlReader.Create(@"c:\temp\locations.xml", settings))
{
#region Deserializar location
XmlSerializer deserializerLoc = new XmlSerializer(typeof(Location), new XmlRootAttribute("location"));
locations = (Location)deserializerLoc.Deserialize(reader);
Location xmlDataLocation = locations;
#endregion
#region Deserializar room
XmlSerializer deserializerRom = new XmlSerializer(typeof(Room));
rooms = (Room)deserializerRom.Deserialize(reader);
Room xmlDataRoom = rooms;
#endregion
Console.Write("cuartos : " + rooms.ToString());
Console.Write("locaciones: " + locations);
}
Console.ReadKey();
}
What I have consulted is that a namespace is missing, but if the process is already done and another error occurs in the same line, choose to leave the namespace without the namespace.
<?xml version="1.0" encoding="utf-8" ?>
<info >
<locations>
<location name="New York">
<Buildings>
<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>
<Buildings>
<location>
<location name="London">
<Buildings>
<Building name="Building45">
<Rooms>
<Room name="Room5">
<Capacity>6<Capacity>
<Room>
<Rooms>
<Building>
<Buildings>
<location>
<locations>
</info>
The first question is why does this error happen?
the second question is well coded to take the data from the xml to the object, I need it for certain XML tags.