Why don’t I get any results using the XML and XPath code below?
This is actually PowerShell but I also tried it with this online tool but again: it output nothing!
I think I’m totally overlooking something!
[xml] $xml = @"
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
</Project>
"@;
Select-Xml "//ItemGroup" $xml | % {
Write-Host $_.Node.GetType();
}
It’s because of the default namespace.
Try
//*[local-name()='ItemGroup'].or
/*/*[local-name()='ItemGroup']or
/*/*All 3 of these should return
ItemGroup.