XPath and *.csproj

前端 未结 3 835
囚心锁ツ
囚心锁ツ 2020-12-06 05:50

I am for sure missing some important detail here. I just cannot make .NET\'s XPath work with Visual Studio project files.

Let\'s load an xml document:



        
3条回答
  •  借酒劲吻你
    2020-12-06 06:45

    Look at the root namespace; you'll have to include an xml-namespace manager and use queries like "//x:ItemGroup", where "x" is your designated alias for the root namespace. And pass the manager into the query. For example:

            XmlDocument doc = new XmlDocument();
            doc.Load("my.csproj");
    
            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
            mgr.AddNamespace("foo", doc.DocumentElement.NamespaceURI);
            XmlNode firstCompile = doc.SelectSingleNode("//foo:Compile", mgr);
    

提交回复
热议问题