How can I handle an empty namespace with XDocument.XPathEvaluate?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-06-16T19:04:33Z Indexed on 2010/06/16 19:12 UTC
Read the original article Hit count: 718

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about xpath