1
我想要什么
检索任务“过期”元素过期。如何在WinRT中使用LinQ过滤空的XML元素?
的XML是什么
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<tasks>
<task>
<title>11111</title>
<due>2012/06/18</due>
</task>
<task>
<title>2121211212</title>
<due></due>
</task>
</tasks>
我的代码
var res = from q in xml.Root.Descendants("task")
where q.Element("due").IsEmpty == false & (Convert.ToDateTime(q.Element("due").Value)).Date < DateTime.Now.Date
select q
是什么错误
类型的异常“Sys系统tem.FormatException'发生在mscorlib.dll中,但未在用户代码中处理
附加信息:String未被识别为有效的DateTime。 如果有这种异常的处理程序,程序可能会安全地继续。
-_-
如果我删除的元素 “因” 是空的任务,错误就走开了。
但不要只用下面的代码过滤空元素?!
q.Element("due").IsEmpty == false
为什么以及如何解决它?