Marco

Marco

  • NA
  • 3
  • 4k

XML serialize multiple classes

Aug 31 2010 11:14 AM
So I've got a bit of a problem I'm made a class that i have to use 7 times (one for each day of the week) I have the serialize set this way

 FileStream stream = new FileStream("C:\\employee.xml", FileMode.OpenOrCreate);
XmlSerializer serializer = new XmlSerializer(typeof(Day));
serializer.Serialize(stream, monday);
serializer.Serialize(stream, tuesday);
serializer.Serialize(stream, wednesday);
serializer.Serialize(stream, thursday);
serializer.Serialize(stream, friday);
serializer.Serialize(stream, saturday);
serializer.Serialize(stream, sunday);

problem is when I unserialize it only works if i only save the class once, is there anything that has to be done differently for more then 1 instance of the same class?

 FileStream stream = new FileStream("C:\\employee.xml", FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(Day));
monday = (Day)serializer.Deserialize(stream);

Thanks :)

Answers (4)