Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从RSS源获取id或链接以及更新日期的最简单方法?_C#_.net_Xml_Linq - Fatal编程技术网

C# 从RSS源获取id或链接以及更新日期的最简单方法?

C# 从RSS源获取id或链接以及更新日期的最简单方法?,c#,.net,xml,linq,C#,.net,Xml,Linq,我尝试使用linq,但失败了,因为我没有xml知识 从rss源获取id或链接并进行更新的最简单方法是什么?(示例提要->) 我不知道如何跳过所有元素,直到第一个条目元素。我也不知道如何从entry元素中提取每个元素的链接和数据,这里有一个简单的示例: var url = "http://stackoverflow.com/feeds/question/1926343"; var rss = new WebClient().DownloadString(url); var doc = XDocum

我尝试使用linq,但失败了,因为我没有xml知识

从rss源获取id或链接并进行更新的最简单方法是什么?(示例提要->)


我不知道如何跳过所有元素,直到第一个条目元素。我也不知道如何从entry元素中提取每个元素的链接和数据,这里有一个简单的示例:

var url = "http://stackoverflow.com/feeds/question/1926343";
var rss = new WebClient().DownloadString(url);
var doc = XDocument.Parse(rss);
var mgr = new XmlNamespaceManager(new NameTable());
var ns = "http://www.w3.org/2005/Atom";
mgr.AddNamespace("atom", ns);

foreach (var entry in doc.XPathSelectElements("/atom:feed/atom:entry", mgr))
{
    var id = entry.Element(XName.Get("id", ns)).Value;
    var link = entry.Element(XName.Get("link", ns)).Attribute("href").Value;
    var updated = entry.Element(XName.Get("updated", ns)).Value;
    Console.WriteLine(id);
    Console.WriteLine("\tLink: " + link);
    Console.WriteLine("\tUpdated: " + updated);
}
这是它生成的输出:

http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c
    Link: http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c
    Updated: 2009-12-18T05:21:53Z
http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926359#1926359
    Link: http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926359#1926359
    Updated: 2009-12-18T04:56:01Z
http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926361#1926361
    Link: http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926361#1926361
    Updated: 2009-12-18T04:56:06Z
http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926365#1926365
    Link: http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926365#1926365
    Updated: 2009-12-18T04:58:08Z
http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926446#1926446
    Link: http://stackoverflow.com/questions/1926343/alternative-to-thead-sleep-in-c/1926446#1926446
    Updated: 2009-12-18T05:21:53Z