I am reading XML file so that I can have all the necessary information to make a windows service.
The problem is that, I have to read all the task in XmlNodeList and then iterate to each Task element and read attribute.
My XML file look like this:
<Tasks>
<Task name="taskname1" type="tasktype1">
<Occurrence starttime="09:00" repeat="01:00" endtime="17:00" />
<FreeSpace disk=”C” />
</Task>
<Task name="taskname2" type="tasktype2">
<Occurrence startime="11:00" repeat="00:05" endtime="13:00" />
</Task>
</Tasks>
So what I want is that each task will be saved in a xmlNodeList and then for each task i have to read its child elements attribute and its values.
What I have achieved so far is that, I have been able to get the value of only first task which is free space on C.
My code is just reading first task.
XmlNodeList xnList = xmlDoc.SelectNodes("/Tasks/Task");
foreach (XmlNode task in xnList)
{
taskName = task.Attributes["name"].Value;//Name
taskType = task.Attributes["type"].Value;//Type
Console.WriteLine(taskName + " " + taskType);
}
XmlNodeList List = xmlDoc.SelectNodes("/Tasks/Task/Occurrence");
foreach (XmlNode task1 in List)
{
taskStartTime = task1.Attributes["starttime"].Value;//starttime
taskRepeat = task1.Attributes["repeat"].Value;//rpt
taskEndTime = task1.Attributes["endtime"].Value;//endtime
Console.WriteLine(taskStartTime + " " + taskRepeat + " " + taskEndTime);
}