I am trying to select all nodes using root.SelectNodes() with XPath. For reference, see msdn-documentation.
In the following document explained, you can also search for nodes that contain attributes (correct me if this is actually a wrong understanding).
So I used the following line of code:
XmlNodeList nodes = projectDoc.DocumentElement.SelectNodes("descendant::Compile[attribute::Include]");
And I am trying to read the following data:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<ItemGroup>
<Compile Include="ArrayExtensions.cs" />
<Compile Include="ArrayIterator.cs" />
<Compile Include="AutoInitializeAttribute.cs" />
<Compile Include="AutoInitializePriority.cs" />
<Compile Include="AutoRegisterAttribute.cs" />
<Compile Include="FormattableExtensions.cs" />
<Compile Include="Mathematics\PrimeNumbers.cs" />
</ItemGroup>
</Project>
As shown in the code-sample above, I want to get all the XmlNodes that contain the Include-attribute. However, when I execute my code, nodes contains 0 elements.
What am I doing wrong here?
Compileelements in thehttp://schemas.microsoft.com/developer/msbuild/2003namespace. Is there any reason you need to do this in XPath? With LINQ to XML this would be trivial.