Cannot Deserialize XML File into a List

israti

New Member
My problem is, my program isn't taking data from my XML file and putting it into a listI can save data just fine but I can't load it back.Here is my Save function\[code\] public void Save_Data_Click(object sender, EventArgs e) { XmlSerializer PSR = new XmlSerializer(typeof(Pickup)); XmlSerializer DSR = new XmlSerializer(typeof(Delivery)); TextWriter PickupStream = new StreamWriter(@"Pickup Save Data.xml"); TextWriter DeliveryStream = new StreamWriter(@"Delivery Save Data.xml"); PSR.Serialize(PickupStream, thePickup); DSR.Serialize(DeliveryStream, theDelivery); DeliveryStream.Close(); PickupStream.Close(); MessageBox.Show("All data saved!"); }\[/code\]Here is my xml load code\[code\] XmlSerializer SerializerObj = new XmlSerializer(typeof(Pickup)); FileStream ReadFileStream = new FileStream(@"Pickup Save Data.xml", FileMode.Open, FileAccess.Read, FileShare.Read); Pickup LoadedObj = (Pickup)SerializerObj.Deserialize(ReadFileStream); ReadFileStream.Close();\[/code\]Here is my Pickup Class\[code\] namespace Vans { [Serializable] public class Pickup { public List<Pickups> Pickups = new List<Pickups>(); public void addPickup(Pickups Pic) { Pickups.Add(Pic); } public List<String> listPickups() { List<String> listPickups = new List<string>(); foreach (Pickups pick in Pickups) { String pickupString = pick.ToString(); listPickups.Add(pickupString); } return listPickups; } public Pickups getPickup(int i) { int c = 0; foreach (Pickups Pic in Pickups) { if (i == c) return Pic; c++; } return null; } }}\[/code\]My Delivery class is the same as the Pickup class.Edit\[code\] <?xml version="1.0" encoding="utf-8"?> <Pickup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Pickups> <Pickups> <pickupfirstname>dsf</pickupfirstname> <pickuplastname>sdf</pickuplastname> <pickupdeliveryaddress>sd</pickupdeliveryaddress> <pickuptime>dsf</pickuptime> </Pickups> </Pickups></Pickup>\[/code\]this is some sample XML code
 
Back
Top