相关疑难解决方法(0)

使用XPath从Atom XML文档中选择无节点?

我正在尝试以编程方式解析Atom提要.我将原子XML下载为字符串.我可以将XML加载到XmlDocument.但是,我无法使用XPath遍历文档.每当我尝试,我都会null.

我一直在使用这个Atom提要作为测试:http://steve-yegge.blogspot.com/feeds/posts/default

除了我使用" " 时,调用SelectSingleNode()总是返回.这是我现在正在尝试的:null/

using (WebClient wc = new WebClient())
{
    string xml = wc.DownloadString("http://steve-yegge.blogspot.com/feeds/posts/default");
    XmlNamespaceManager nsMngr = new XmlNamespaceManager(new NameTable());
    nsMngr.AddNamespace(string.Empty, "http://www.w3.org/2005/Atom");
    nsMngr.AddNamespace("app", "http://purl.org/atom/app#");
    XmlDocument atom = new XmlDocument();
    atom.LoadXml(xml);
    XmlNode node = atom.SelectSingleNode("//entry/link/app:edited", nsMngr);
}
Run Code Online (Sandbox Code Playgroud)

我以为它可能是因为我的XPath,所以我也尝试了一个简单的根节点查询,因为我知道root应该工作:

// I've tried both with & without the nsMngr declared above
XmlNode node = atom.SelectSingleNode("/feed");
Run Code Online (Sandbox Code Playgroud)

无论我做什么,似乎都无法选择任何东西.显然我错过了一些东西,我只是无法弄清楚是什么.为了使XPath能够在这个Atom提要上工作,我需要做些什么?

编辑

虽然这个问题有答案,但我发现这个问题几乎完全重复:SelectNodes不能处理stackoverflow feed

c# xml xpath xmldocument atom-feed

6
推荐指数
1
解决办法
7076
查看次数

标签 统计

atom-feed ×1

c# ×1

xml ×1

xmldocument ×1

xpath ×1