How to read XML Data in C# ?



I'm making a simple to do list and want to store the Tasks in a XML File. My XML File looks like this:



<Task>
<Title>Make a List</Title>
<Description>I should make a List!</Description>
<Done>false</Done>
</Task>


Every Task is in the Tag which stores the Title, Description and if it's done. (First time I'm using XML)


I want to generate on FormLoad for each it should make a CheckBox with


Text = <Title> ToolTip = "<Description>" Checked = <Done>


Until now my Code looks like this:



void MainFormLoad(object sender, EventArgs e)
{
var doc = XDocument.Load(Application.StartupPath + "\\tasker.xml");

var Title = doc.Root.Descendants().Single(d => d.Name == "Title").Value;
var Description = doc.Root.Descendants().Single(d => d.Name == "Description").Value;
var Done = doc.Root.Descendants().Single(d => d.Name == "Done").Value;

MessageBox.Show(Title.ToString() + Environment.NewLine + Description.ToString() ); // Just for Testing
}


This works great but how can I make this for more than 1 Task ?


Tiada ulasan:

Catat Ulasan