Using Xpath With Default Namespace in C#

前端 未结 13 1512
别那么骄傲
别那么骄傲 2020-11-22 03:02

I\'ve got an XML document with a default namespace. I\'m using a XPathNavigator to select a set of nodes using Xpath as follows:

XmlElement myXML = ...;           


        
13条回答
  •  长发绾君心
    2020-11-22 03:48

    Or, if anyone should be using an XPathDocument, like me:

    XPathDocument xdoc = new XPathDocument(file);
    XPathNavigator nav = xdoc.CreateNavigator();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
    nsmgr.AddNamespace("y", "http://schemas.microsoft.com/developer/msbuild/2003");
    XPathNodeIterator nodeIter = nav.Select("//y:PropertyGroup", nsmgr);
    

提交回复
热议问题