How can I handle an empty namespace with XDocument.XPathEvaluate?
- by Kevin
I'm trying to use XDocument and XPathEvaluate to get values from the woot.com feed. I'm handling other namespaces fine, but this example is giving me problems.
<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=' --!>
So I try this:
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", xdwn.Namespace);
val is always null. I'm using ns: from the suggestion from VS 2010 XPath Navigator plugin. Any thoughts on how to handle this?