<channel>
<title>Best Web Gallery - Flash + CSS Gallery</title>
<link>http://bestwebgallery.com</link>
<description>Featuring the world best web design</description>
<pubDate>09 Dec 2009</pubDate>
<generator>http://wordpress.org/?v=2.3.2</generator>
<language>en</language>
</channel>
<channel>
<title>Best Web Gallery - Flash + CSS Gallery</title>
<link>http://bestwebgallery.com</link>
<description>Featuring the world best web design</description>
// pubDate missing
<generator>http://wordpress.org/?v=2.3.2</generator>
<language>en</language>
</channel>
XDocument rssFeed = XDocument.Load(url);
var feedResources = from details in rssFeed.Descendants("channel")
select new feedResource
{
Title = details.Element("title").Value,
Host = details.Element("link").Value,
Description = details.Element("description").Value,
PublishedOn = DateTime.Parse(details.Element("pubDate").Value),
Generator = details.Element("generator").Value,
Language = details.Element("language").Value
};
我們如何在嘗試獲取元素「pubDate」或其他元素之前檢查此處,因爲如果未檢查,則會拋出空引用異常?c#LINQ to XML查詢表達式爲elemennt exhist?
哦DateTime.Now,這很酷。我不知道。 +1 – Zooba 2009-12-09 20:43:49
感謝隊友,出色的工作 – 2009-12-09 21:48:47