【发布时间】:2011-06-17 01:47:03
【问题描述】:
<?xml version="1.0" encoding="UTF-8" ?>
<Accounts>
<Account id="usama" password="3210" lastUpdated="6/16/2011 11:21:59 AM" nextUpdate="6/16/2011 11:36:59 AM">
<SubAccount id="false">
<Url>yahoo</Url>
<Review>not so good</Review>
</SubAccount>
<SubAccount id="false">
<Url>google</Url>
<Review>as good as heard.</Review>
</SubAccount>
</Account>
</Accounts>
假设我想获取所有最后更新日期小于或等于今天(假设 6/17/2011)日期的结果。
所以我的结果应该是这样的。
Accout id =usama ,passwod =3210 ,url=yahoo, review=not so good
Accout id =usama ,passwod =3210 ,url=google, review=as good as heard
到目前为止,我已经编写了查询
var q = from c in doc.Descendants("Accounts")
from a in c.Descendants("Account")
where a.Attribute("nextUpdate").Value == "6/16/2011 11:36:59 AM"
select new
{
accountName = a.Attribute("id").Value,
password = a.Attribute("password").Value,
url = a.Descendants("SubAccount").Descendants("Url").ToString()
//review=a.Attribute("nextUpdate").Value
}
我可以正常获取用户名和密码,但我不知道如何获取 URL 和查看。另外如何将 where 子句中的 Attribute("nextUpdate") 转换为日期时间,以便我可以将其与日期进行比较?
【问题讨论】:
标签: c# .net linq linq-to-xml