ani*_*lca 1 c# linq-to-xml feedparser
如何从此Feed中获取"入口"节点
http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563348
我试过linq到xml,但我认为因为代码后面的条目标签的现有属性不起作用.
string url = "http://www.google.com/alerts/feeds/14392773026536511983/5526937985735563348";
WebClient c = new WebClient();
string xml = ASCIIEncoding.Default.GetString(c.DownloadData(url));
XDocument doc = XDocument.Parse(xml);
var entries = doc.Descendants("entry");
提前致谢,
您没有指定命名空间.试试这个:
XNamespace atom = "http://www.w3.org/2005/Atom";
var entries = doc.Descendants(atom + "entry");
顺便说一句,我不会使用ASCII,或者DownloadData......用来WebClient.DownloadString为你处理编码.或者确实,只需使用XDocument.Load(url):
例如:
string url = ...;
XDocument doc = XDocument.Load(url);
XNamespace atom = "http://www.w3.org/2005/Atom";
var entries = doc.Descendants(atom + "entry");
Console.WriteLine(entries.Count()); // Prints 20
| 归档时间: | 
 | 
| 查看次数: | 292 次 | 
| 最近记录: |