我正在尝试使用XDocument和XPathEvaluate从woot.com提要中获取值。我正在处理其他命名空间,但这个例子给我带来了问题。如何使用XDocument.XPathEvaluate处理空名称空间?
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<category text="Comedy" xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd">
</category>
<!-- this is a problem node, notice 'xmlns=' --!>
所以我试试这个:
XmlNamespaceManager man = new XmlNamespaceManager(nt);
man.AddNamespace("ns", "http://www.w3.org/2000/xmlns/");
// i've also tried man.AddNamespace("ns", string.Empty);
xDocument.Namespace = man;
var val = xDocument.XPathEvaluate("/rss/channel/ns:category/@text", xDocument.Namespace);
VAL总是空。我使用ns:来自VS 2010 XPath Navigator插件的建议。有关如何处理这个问题的任何想法?
什么是'xdwn.Namespace'?在提供的代码中未定义xdwn。 – 2010-06-16 21:09:19
@Dimitre Novatchev - 应该是xDocument,我编辑了这个问题。感谢您检查我的问题。 – Aligned 2010-06-16 21:44:44