问题
all.
I am interested in pulling the Last Build Date information from an RSS feed. I will use the information to let the user know when there is a new feed out.
Here is the RSS feed...
<?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>
On load, the application will pull the initial lastBuildDate and store it in a label then use a timer to compare the label to a newly pulled value every few minutes. For example:
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;
}
I'm just not certain on how to pull the lastBuildDate in the private void getLastBuild(). I'm not great with the whole nodes thing. Any help would be great on this last piece of the puzzle. Thanks!
回答1:
Use LINQ-to-XML:
from buildDate in xmlData.Descendants("lastBuildDate")
select buildDate.Value
Where xmlData
is the rss string you loaded.
来源:https://stackoverflow.com/questions/21773242/c-sharp-pulling-rss-lastbuilddate