SelectNodes not working on stackoverflow feed

别来无恙 提交于 2019-11-27 15:02:46

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".

You might need to add a 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);

It is needed if you want to call SelectNodes on a document that uses them. What error are you seeing?

You've guessed correctly: you're asking for nodes not in a namespace, but these nodes are in a namespace.

Description of the problem and solution: http://weblogs.asp.net/wallen/archive/2003/04/02/4725.aspx

I just want to use..

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

but, what namespace do the entry 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?

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

Something like that?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!