SelectNodes无法处理stackoverflow Feed

我正在尝试在我的rss阅读器中添加对stackoverflow提要的支持,但SelectNodesSelectSingleNode没有任何效果。 这可能与我还不了解的ATOM和xml命名空间有关。

我已经通过从feed标签中删除所有属性来实现它,但这是一个黑客,我想正确地做到这一点。 那么,你如何使用带有primefaces馈送的SelectNodes

这是一个饲料片段。

  StackOverflow.com - Questions tagged: c  Check out the latest from StackOverflow.com 2008-08-24T12:25:30Z http://stackoverflow.com/feeds/tag/c http://www.creativecommons.org/licenses/by-nc/2.5/rdf  http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server What is the best way to communicate with a SQL server?  Ed  2008-08-22T05:09:04Z 2008-08-23T04:52:39Z <p>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?</p>  2   

解决方案

 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); 

不要将XML文件中的命名空间名称与命名空间管理器的命名空间名称混淆。 他们都是捷径,他们不一定要匹配。

因此,您可以将“ http://www.w3.org/2005/Atom ”注册为“atom”,然后为“atom:entry”执行SelectNodes。

您可能需要添加XmlNamespaceManager。

 XmlDocument document = new XmlDocument(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable); nsmgr.AddNamespace("creativeCommons", "http://backend.userland.com/creativeCommonsRssModule"); // AddNamespace for other namespaces too. document.Load(feed); 

如果要在使用它们的文档上调用SelectNodes,则需要它。 你看到什么错误?

您已经猜对了:您要求的节点不在命名空间中,但这些节点位于命名空间中。

问题描述和解决方案: http : //weblogs.asp.net/wallen/archive/2003/04/02/4725.aspx

我只是想用..

 XmlNodeList itemList = xmlDoc.DocumentElement.SelectNodes("entry"); 

但是, 条目标签属于哪个命名空间? 我会假设xmlns =“http://www.w3.org/2005/Atom”,但它没有标题,那么我将如何添加该命名空间?

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

那样的东西?