开发者

Showing Multiple XML Data Entries With the Same Node Value

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 searc开发者_如何学Pythonh an XML file and use multiple entries in a scenario such as this? Thanks.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜