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

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

<p>Here's a snippet of the feed.</p>

<pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;feed xmlns="http://www.w3.org/2005/Atom" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:thr="http://purl.org/syndication/thread/1.0"&gt;

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


 &lt;entry&gt;
   &lt;id&gt;http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server&lt;/id&gt;
   &lt;title type="html"&gt;What is the best way to communicate with a SQL server?&lt;/title&gt;
   &lt;category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c" /&gt;&lt;category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="c++" /&gt;&lt;category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="sql" /&gt;&lt;category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="mysql" /&gt;&lt;category scheme="http://stackoverflow.com/feeds/tag/c/tags" term="database" /&gt;  
   &lt;author&gt;&lt;name&gt;Ed&lt;/name&gt;&lt;/author&gt;
   &lt;link rel="alternate" href="http://stackoverflow.com/questions/22901/what-is-the-best-way-to-communicate-with-a-sql-server" /&gt;
   &lt;published&gt;2008-08-22T05:09:04Z&lt;/published&gt;
   &lt;updated&gt;2008-08-23T04:52:39Z&lt;/updated&gt;
   &lt;summary type="html"&gt;&amp;lt;p&amp;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?&amp;lt;/p&amp;gt;&lt;/summary&gt;
   &lt;link rel="replies" type="application/atom+xml" href="http://stackoverflow.com/feeds/question/22901/answers" thr:count="2"/&gt;
   &lt;thr:total&gt;2&lt;/thr:total&gt;
 &lt;/entry&gt;


&lt;/feed&gt;
</code></pre>

<p><br/></p>

<h2>The Solution</h2>

<pre><code>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);
</code></pre>

[{'answer_id': 24738, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 2, 'selected': False, 'text': '<p>You\'ve guessed correctly: you\'re asking for nodes not in a namespace, but these nodes are in a namespace.</p>\n\n<p>Description of the problem and solution: <a href="http://weblogs.asp.net/wallen/archive/2003/04/02/4725.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/wallen/archive/2003/04/02/4725.aspx</a></p>\n'}, {'answer_id': 24740, 'author': 'Julio César', 'author_id': 2148, 'author_profile': 'https://Stackoverflow.com/users/2148', 'pm_score': 3, 'selected': False, 'text': '<p>You might need to add a XmlNamespaceManager.</p>\n\n<pre><code>XmlDocument document = new XmlDocument();\nXmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);\nnsmgr.AddNamespace("creativeCommons", "http://backend.userland.com/creativeCommonsRssModule");\n// AddNamespace for other namespaces too.\ndocument.Load(feed);\n</code></pre>\n\n<p>It is needed if you want to call SelectNodes on a document that uses them. What error are you seeing?</p>\n'}, {'answer_id': 24753, 'author': 'sieben', 'author_id': 1147, 'author_profile': 'https://Stackoverflow.com/users/1147', 'pm_score': 0, 'selected': False, 'text': '<p>I just want to use..</p>\n\n<pre><code>XmlNodeList itemList = xmlDoc.DocumentElement.SelectNodes("entry");\n</code></pre>\n\n<p>but, what namespace do the <strong>entry</strong> tags fall under? I would assume xmlns="http://www.w3.org/2005/Atom", but it has no title so how would I add that namespace?</p>\n\n<pre><code>XmlDocument document = new XmlDocument();\nXmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);\nnsmgr.AddNamespace("", "http://www.w3.org/2005/Atom");\ndocument.Load(feed);\n</code></pre>\n\n<p>Something like that?</p>\n'}, {'answer_id': 24755, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 4, 'selected': True, 'text': '<p>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.</p>\n\n<p>So you can register "<a href="http://www.w3.org/2005/Atom" rel="noreferrer">http://www.w3.org/2005/Atom</a>" as "atom", and then do a SelectNodes for "atom:entry".</p>\n'}]
['https://Stackoverflow.com/questions/24734', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1147/']