So I've made a Task Scheduling application (for learning purposes). The program currently saves all the data in simple text form. I use Regex to split the data up and assign it to the appropriate variables.
I don't really like this way of doing things as it seems messy and it's not very clean looking code wise. I think learning some XML interaction would be a good way to extend my knowledge.
This is the way I would like my XML file layout to be:
<?xml version="1.0"?>
<Tasks>
<Task1>
<Name>Shutdown</Name>
<Location>C:\WINDOWS\system32\shutdown.exe</Location>
<Arguments>-s -f -t 30</Arguments>
<RunWhen>
<Time>8:00:00 a.m.</Time>
<Date>18/03/2011</Date>
<Days>
<Monday>false</Monday>
<Tuesday>false</Tuesday>
<Wednesday>false</Wednesday>
<Thursday>false</Thursday>
<Friday>false</Friday>
<Saturday>false</Saturday>
<Sunday>false</Sunday>
<Everyday>true</Everyday>
<RunOnce>false</RunOnce>
</Days>
</RunWhen>
<Enabled>true</Enabled>
</Task1>
</Tasks>
I have worked out how to read the XML file using this method:
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("Tasks.xml");
XmlNodeList searchNode = xmlDocument.GetElementsByTagName(tagName);
MessageBox.Show(searchNode[0].InnerText);
So if the XML contain multiple Tasks (tagged as Task1, Task2 etc) would this be an effective way of loading the data into my Tasks class (using a List<> that contains multiple tasks)? Or is there and easier way?
Also when it comes to saving the stored Tasks I need to take the values data the Tasks class and save it as an XML File, this means if I've added another Task the XML file will have to have another Task[index] tag like in the XML file above? Is there a way of doing this nicely? Some pointer would be great.
Any help is appreciated :D