所有
我有兴趣从RSS源中提取最后构建日期信息。我将使用这些信息让用户知道何时有新的Feed。
这是RSS提要......
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>User's Facebook Notifications</title>
<link>https://www.facebook.com/notifications?id=USERIDHERE</link>
<description>User's Facebook Notifications</description>
<language>en-us</language>
<category domain="Facebook">NotificationSyndicationFeed</category>
<generator>Facebook Syndication</generator>
<docs>http://www.rssboard.org/rss-specification</docs>
<lastBuildDate>Thu, 13 Feb 2014 21:19:52 -0500</lastBuildDate>
<webMaster>webmaster@facebook.com</webMaster>
</channel>
<access:restriction relationship="deny" xmlns:access="http://www.bloglines.com/about/specs/fac-1.0" />
</rss>
在加载时,应用程序将拉出初始的lastBuildDate并将其存储在标签中,然后使用计时器将标签与每隔几分钟新拉出的值进行比较。例如:
private void frmFacebookRSS(object sender, EventArgs e)
{
getLastBuild();
DateTime now = DateTime.Now;
lblLastBuild.Text = LastBuild;
}
private void tmrUpdate_Tick(object sender, EventArgs e)
{
getLastBuild();
DateTime now = DateTime.Now;
if (lblLastBuild.text != LastBuild)
{
System.Beep // Or whatever desired output
lblLastBuild.Text = LastBuild;
}
我只是不确定如何在private void getLastBuild()中提取lastBuildDate。我对整个节点的事情并不好。在这最后一块拼图中,任何帮助都会很棒。谢谢!
答案 0 :(得分:0)
使用LINQ-to-XML:
from buildDate in xmlData.Descendants("lastBuildDate")
select buildDate.Value
xmlData
是你加载的rss字符串。