XPath and *.csproj

前端 未结 3 838
囚心锁ツ
囚心锁ツ 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:40

    You probably need to add a reference to the namespace http://schemas.microsoft.com/developer/msbuild/2003.

    I had a similar problem, I wrote about it here. Do something like this:

    XmlDocument xdDoc = new XmlDocument();
    xdDoc.Load("blah/blah.csproj");
    
    XmlNamespaceManager xnManager =
     new XmlNamespaceManager(xdDoc.NameTable);
    xnManager.AddNamespace("tu",
     "http://schemas.microsoft.com/developer/msbuild/2003");
    
    XmlNode xnRoot = xdDoc.DocumentElement;
    XmlNodeList xnlPages = xnRoot.SelectNodes("//tu:ItemGroup", xnManager);
    

提交回复
热议问题