I have a function which writes all the Information of objects I have in a list into a XML file.
public static void UpdateXML()
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter Writer = XmlWriter.Create("path", settings);
Writer.WriteStartDocument();
Writer.WriteStartElement("Accounts");
foreach (var acc in Bank.Bankaccountlist)
{
Writer.WriteStartElement("Account");
Writer.WriteAttributeString("ID", acc.id.ToString());
Writer.WriteElementString("Name", acc.GetName());
Writer.WriteElementString("Lastname", acc.GetLastname());
Writer.WriteElementString("Balance", acc.GetBalance().ToString());
Writer.WriteEndElement();
}
Writer.WriteEndElement();
Writer.Flush();
Writer.Close();
}
Now, when the Program gets closed, all the Data is still in the file. So as soon as the Program starts again, it should create all the old objects again (creating an Account
object will automatically put it in the list).
Could anyone tell me how that'd be possible?
Note that int id
and double balance
.