Can anyone help me with this code I don't know what is wrong here.. I want to retrieve Data from XML where Date is 2015/9/12 and 2015/9/13.
任何人都可以帮我这个代码我不知道这里有什么问题..我想从XML中检索数据,其中日期是2015/9/12和2015/9/13。
var events = (from item in xdocument.Descendants("Event")
where (string)item.Element("Date") == "2015/9/12" &&
(string)item.Element("Date") == "2015/9/13"
select (string)item.Element("Date")).ToList();
foreach (string name in events)
{
MessageBox.Show(name);
}
Here is my XML file.
这是我的XML文件。
<?xml version="1.0" encoding="utf-8"?>
<Events>
<Event ID="0">
<Name>test</Name>
<Date>2015/9/12</Date>
<Priority>0</Priority>
<Created_at>0000</Created_at>
</Event>
<Event ID="1">
<Name>test1</Name>
<Date>2015/9/13</Date>
<Priority>0</Priority>
<Created_at>0000</Created_at>
</Event>
<Event ID="2">
<Name>test2</Name>
<Date>2015/9/15</Date>
<Priority>2</Priority>
<Created_at>0000</Created_at>
</Event>
</Events>
1 个解决方案
#1
0
First thing you need to do is modify your xml. You have tag mismatches on your date tags. You have <Date>2015/9/12</Data>
. Notice your ending tag says Data instead of Date. Then you can do the following:
您需要做的第一件事是修改您的xml。您的日期标记上有标记不匹配。您有
var events = doc.Descendants("Event").Where(x => x.Element("Date").Value == "2015/9/12" || x.Element("Date").Value == "2015/9/13");
#1
0
First thing you need to do is modify your xml. You have tag mismatches on your date tags. You have <Date>2015/9/12</Data>
. Notice your ending tag says Data instead of Date. Then you can do the following:
您需要做的第一件事是修改您的xml。您的日期标记上有标记不匹配。您有
var events = doc.Descendants("Event").Where(x => x.Element("Date").Value == "2015/9/12" || x.Element("Date").Value == "2015/9/13");