显示多个XML数据条目具有相同的节点值 [英] Showing Multiple XML Data Entries With the Same Node Value

查看:644
本文介绍了显示多个XML数据条目具有相同的节点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了教训的信息中有一个XML文档,如以下内容:

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>



所以,我有一个双赢应用形式表示一天中的不同时间,即按钮:Monday0700Button ,Monday0730Button等

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

我所试图做的是,使用XML数据实例,因此,它会搜索XML文件上的日期发生的所有条目(说01/01/2010)不同时间和颜色的按钮不同的颜色时,有一个匹配的背景。

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.

我如何搜索XML文件,使用一个场景多个条目,如本?
感谢。

How do I search an XML file and use multiple entries in a scenario such as this? Thanks.

推荐答案

要选择一个特定日期的所有XML节点,你可以使用这样的事情(假设你在一个XmlDocument的XML数据的话):

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?

马克

这篇关于显示多个XML数据条目具有相同的节点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆