tags:

views:

178

answers:

1

I have a Xml Document that has lesson information in it, such as the following:

<Lessons>
 <Lesson ID= *GUID number*>
  <Date>01/01/2010</Date>
  <Time>07:00am</Time>
 </Lesson>
 <Lesson ID= *GUID number*>
  <Date>01/01/2010</Date>
  <Time>09:00</Time>
 </Lesson>
<Lessons>

So, I have buttons in a Win App form that represent the different times of day, ie: Monday0700Button, Monday0730Button, etc

What I am trying to do is, use the xml data instances, so that it will search the xml file for all entries that occur on a date (say 01/01/2010) for different times, and color the background of the button a different color when there is a match.

How do I search a Xml file and use mutliple entries in a scenario such as this? Thanks.

+2  A: 

To select all XML nodes for a given date, you can use something like this (assuming you have your XML data in a XmlDocument already):

XmlNodeList allNodes = doc.SelectNodes("/Lessons/Lesson[Date='01/01/2010']");

and then you should be able to iterate over those nodes:

foreach(XmlNode node in allNodes)
{  
   string time = node.SelectSingleNode("Time").InnerText;
}

Does that work for you?

Marc

marc_s
That is looking good. How would I use the individual data found though? So say if <Time> value = "07:00am", change backcolor of Monday0700Button, same thing for the other values of the time node.
The Woo
how to make use of that data is totally up to you - that's what makes your app work! :-) You'll have to find out what to do with each bit of information - can't tell you that...
marc_s
Well can you please at least let me know how I use the string 'time' to get in the right direction? :)
The Woo
I'm very new to c#, and I've taken on a project waaaay over my head! :)
The Woo
Sorry, I have *no idea* what you want to do or achieve - I can't tell you how to get there..... you can compare the string to a particular value ( ` if(time == "08:00") `) and then do something with it, or you could convert it to seconds or whatever - the sky's the limit
marc_s
fair enough :) thanks for your very helpful help with this :)
The Woo
I guess you'll have to think of what you want to do with the information, and then come back and post a new question
marc_s
Is there a way to change the '01/01/2010' to a string that already has a value?
The Woo