不工作的计算器饲料的SelectNodes [英] SelectNodes not working on stackoverflow feed

查看:183
本文介绍了不工作的计算器饲料的SelectNodes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加支持计算器饲料在我的RSS阅读器,但的SelectNodes 的SelectSingleNode 没有任何效果。这大概是与ATOM和XML命名空间,我只是不明白呢。

我得到它通过从供稿标记删除所有属性的工作,但是这是一个黑客,我愿做正确。那么,你如何使用的SelectNodes 与原子饲料?

下面是饲料的一个片段。

&LT; XML版本=1.0编码=UTF-8&GT?; &LT;饲料的xmlns =htt​​p://www.w3.org/2005/Atom的xmlns:项目Creativecommons =htt​​p://backend.userland.com/creativeCommonsRssModule的xmlns:THR =htt​​p://purl.org/联合/线程/ 1.0&GT; C&LT; /标题&GT;:标签的问题 - StackOverflow.com;&LT;标题类型=HTML&GT &LT;链接相对=自我的href =htt​​p://stackoverflow.com/feeds/tag/c类型=应用程序/原子+ XML/&GT; &LT;字幕&GT;检查出最新的来自StackOverflow.com&LT; /字幕&GT; &LT;更新&GT; 2008-08-24T12:25:30Z&LT; /更新&GT; &LT; ID&GT; HTTP://stackoverflow.com/feeds/tag/c< / ID&GT; <creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>  &LT;进入&GT;    <id>http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server</id>    &LT;标题类型=HTML&GT;什么是与SQL服务器通信的最佳方式&LT;?/标题&GT;    &LT;类计划=htt​​p://stackoverflow.com/feeds/tag/c/tags一词=C/&GT;&LT;类计划=htt​​p://stackoverflow.com/feeds/tag/c/标签一词=C ++/&GT;&LT;类计划=http://stackoverflow.com/feeds/tag/c/tags一词=SQL/&GT;&LT;类计划=HTTP:// stackoverflow.com/feeds/tag/c/tags一词=MySQL的/&GT;&LT;类计划=http://stackoverflow.com/feeds/tag/c/tags一词=数据库/&GT;    &LT;笔者&GT;&LT;名称&gt; ED&LT; /名称&gt;&LT; /笔者&GT;    &LT;链接相对=替代 href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" /&GT;    &LT;出版&GT; 2008-08-22T05:09:04Z&LT; /发表&GT;    &LT;更新&GT; 2008-08-23T04:52:39Z&LT; /更新&GT;    &LT;摘要类型=HTML&GT;&放大器; LT; P&放大器; GT;我将使用C / C ++,并想知道跟一个MySQL服务器的最佳方式。我应该使用随服务器安装的图书馆吗?难道他们有什么好的图书馆,我应该考虑比官方的另外一个和放大器; LT; / P&放大器; GT;&LT; /总结&gt;    &LT;链接相对=回复类型=应用程序/原子+ XML的href =htt​​p://stackoverflow.com/feeds/question/22901/answers​​THR:数=2/&GT;    &LT; THR:总&GT; 2'; / THR:总&GT;  &LT; /进入&GT; &LT; /饲料&GT;


解决方案

  XmlDocument的文档=新的XmlDocument();
XmlNamespaceManager的nsmgr =新的XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace(原子,http://www.w3.org/2005/Atom);
doc.Load(饲料);

//成功
XmlNodeList中ITEMLIST = doc.DocumentElement.SelectNodes(原子:入门,nsmgr);
 

解决方案

不要与您的命名空间管理器中的命名空间名称的XML文件中混淆了命名空间名称。他们都是快捷方式,而他们不一定匹配。

所以,你可以注册http://www.w3.org/2005/Atom作为原子,然后做的SelectNodes为原子:条目。

I'm trying to add support for stackoverflow feeds in my rss reader but SelectNodes and SelectSingleNode have no effect. This is probably something to do with ATOM and xml namespaces that I just don't understand yet.

I have gotten it to work by removing all attributes from the feed tag, but that's a hack and I would like to do it properly. So, how do you use SelectNodes with atom feeds?

Here's a snippet of the feed.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:thr="http://purl.org/syndication/thread/1.0">

<title type="html">StackOverflow.com - Questions tagged: c</title>
<link rel="self" href="http://stackoverflow.com/feeds/tag/c" type="application/atom+xml" />
<subtitle>Check out the latest from StackOverflow.com</subtitle>
<updated>2008-08-24T12:25:30Z</updated>
<id>http://stackoverflow.com/feeds/tag/c</id>
<creativeCommons:license>http://www.creativecommons.org/licenses/by-nc/2.5/rdf</creativeCommons:license>


 <entry>
   <id>http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server</id>
   <title type="html">What is the best way to communicate with a SQL server?</title>
   <category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c++" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="sql" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="mysql" /><category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="database" />  
   <author><name>Ed</name></author>
   <link rel="alternate" href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" />
   <published>2008-08-22T05:09:04Z</published>
   <updated>2008-08-23T04:52:39Z</updated>
   <summary type="html">&lt;p&gt;I am going to be using c/c++, and would like to know the best way to talk to a MySQL server.  Should I use the library that comes with the server installation?  Are they any good libraries I should consider other than the official one?&lt;/p&gt;</summary>
   <link rel="replies" type="application/atom+xml" href="http://stackoverflow.com/feeds/question/22901/answers" thr:count="2"/>
   <thr:total>2</thr:total>
 </entry>


</feed>


The Solution

XmlDocument doc = new XmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
doc.Load(feed);

// successful
XmlNodeList itemList = doc.DocumentElement.SelectNodes("atom:entry", nsmgr);

解决方案

Don't confuse the namespace names in the XML file with the namespace names for your namespace manager. They're both shortcuts, and they don't necessarily have to match.

So you can register "http://www.w3.org/2005/Atom" as "atom", and then do a SelectNodes for "atom:entry".

这篇关于不工作的计算器饲料的SelectNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆