Frage

Ich versuche, Unterstützung für Stackoverflow-Feeds in meinem RSS-Reader, aber Select und SelectSingleNode haben keine Wirkung. Dies ist wahrscheinlich etwas mit ATOM-und XML-Namensräumen zu tun, dass ich einfach nicht verstehen noch.

Ich habe es, indem Sie alle Attribute aus dem Feed Tag zur Arbeit bekommen, aber das ist ein Hack, und ich mag es richtig machen. So, wie verwenden Sie Select mit Atom-Feeds?

Hier ist ein Ausschnitt aus dem 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>


Die Lösung

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);
War es hilfreich?

Lösung

Sie den Namespace-Namen in der XML-Datei mit dem Namespace-Namen für Ihren Namespace-Manager nicht verwirren. Sie sind beide Verknüpfungen und sie müssen nicht unbedingt übereinstimmen.

So können Sie sich registrieren „ http://www.w3.org/2005/Atom“als‚Atom‘und dann ein Select tun für‚Atom. Eintrag‘

Andere Tipps

Sie müssen möglicherweise einen XmlNamespaceManager hinzuzufügen.

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

Es ist erforderlich, wenn Sie Select auf einem Dokument aufrufen möchten, die sie verwendet. Welche Fehler sehen Sie?

Sie haben richtig geraten: Sie Knoten nicht in einem Namespace sind gefragt, aber diese Knoten sind in einem Namespace

.

Beschreibung des Problems und Lösung: http: // weblogs.asp.net/wallen/archive/2003/04/02/4725.aspx

Ich will nur verwenden ..

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

aber, welche Namespace tun, um die Eintrag -Tags fallen unter? Ich würde Xmlns annehmen = „http://www.w3.org/2005/Atom“, aber es hat keinen Titel, so wie würde ich diesen Namespace hinzufügen?

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

So etwas wie das?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top