Lets say I have an item
, which has fields(properties)
And I have 10-15 items>
Your options will be:
Store the objects and the read them in your code.
Write XML code example:
public void WriteXML()
{
Book overview = new Book();
overview.title = "Serialization Overview";
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(Book));
System.IO.StreamWriter file = new System.IO.StreamWriter(
@"c:\temp\SerializationOverview.xml");
writer.Serialize(file, overview);
file.Close();
}
Read XML code example:
public void Read(string fileName)
{
XDocument doc = XDocument.Load(fileName);
foreach (XElement el in doc.Root.Elements())
{
Console.WriteLine("{0} {1}", el.Name, el.Attribute("id").Value);
Console.WriteLine(" Attributes:");
foreach (XAttribute attr in el.Attributes())
Console.WriteLine(" {0}", attr);
Console.WriteLine(" Elements:");
foreach (XElement element in el.Elements())
Console.WriteLine(" {0}: {1}", element.Name, element.Value);
}
}