Nic*_*ski 0 .net c# linq-to-xml atom-feed
使用XDocument和Descendants方法.
//first problem 'entries' doesn't fetch at all
var entries = xmlDoc.Descendants(XName.Get("entry"))
//neither does
// xmlDoc.Descendants("entry")
var ids = from e in entries
select e.Element(XName.Get("id")).Value;
Run Code Online (Sandbox Code Playgroud)
相同的XDocument代码适用于更详细的博客提要,即我的博客:http://blog.nick.josevski.com/feed/一个片段在这里:http://pastebin.com/KU65dgwL其中'条目' element替换为'item','id'替换为'link'.
为了测试任何建议,我创建了一个演示该问题的LinqPad代码要点.
我错过了一些明显的东西吗 我已经试过的各种组合.Elements() .Elements("entry")和公正的.Descendants(),然后试图进一步筛选没有运气了.
这是我正在努力从以下位置提取入口/标识节点的XML:
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Author</title>
<subtitle type="text">subtitle</subtitle>
<link rel="alternate" href="http://www.site.com/blog" />
<entry>
<id>http://www.site.com/a-blog-post</id>
<title type="text">Title Of Blog Post</title>
...
<entry>
<id>http://www.site.com/another-blog-post</id>
<title type="text">Title Of Another Blog Post</title>
Run Code Online (Sandbox Code Playgroud)
您缺少XML命名空间:
XNamespace ns = "http://www.w3.org/2005/Atom";
var entries = xmlDoc.Descendants(ns + "entry");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1175 次 |
| 最近记录: |