Which namespace is necessary to use SelectSingleNode() method (using default namespace and can't use the method)

后端 未结 1 728
不知归路
不知归路 2020-12-22 04:10

Hi I have xml file (which is actually msbuild file) that uses different namespace




        
相关标签:
1条回答
  • 2020-12-22 04:51

    You need to use the correct namespace, which is "http://schemas.microsoft.com/developer/msbuild/2003".

    Try

    XmlDocument xml = new XmlDocument();
    xml.Load("ref.props");        
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
    nsmgr.AddNamespace("ms", "http://schemas.microsoft.com/developer/msbuild/2003");
    
    XmlNode platform_node
      = xml.SelectSingleNode("/ms:Project/ms:PropertyGroup[contains(@Condition, '1111')]",
                             nsmgr);
    

    Don't confuse the namespace prefix (which was empty in the XML) with the namespace, which is "http://schemas.microsoft.com/developer/msbuild/2003".

    0 讨论(0)
提交回复
热议问题