I’m trying a very basic XPath on this xml (same as below), and it doesn’t find anything. I’m trying both .NET and this website, and XPaths such as //PropertyGroup, /PropertyGroup and //MSBuildCommunityTasksPath are simply not working for me (they compiled but return zero results).
Source XML:
<?xml version='1.0' encoding='utf-8'?> <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <!-- $Id: FxCop.proj 114 2006-03-14 06:32:46Z pwelter34 $ --> <PropertyGroup> <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\MSBuild.Community.Tasks\bin\Debug</MSBuildCommunityTasksPath> </PropertyGroup> <Import Project='$(MSBuildProjectDirectory)\MSBuild.Community.Tasks\MSBuild.Community.Tasks.Targets' /> <Target Name='DoFxCop'> <FxCop TargetAssemblies='$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll' RuleLibraries='@(FxCopRuleAssemblies)' AnalysisReportFileName='Test.html' DependencyDirectories='$(MSBuildCommunityTasksPath)' FailOnError='True' ApplyOutXsl='True' OutputXslFileName='C:\Program Files\Microsoft FxCop 1.32\Xml\FxCopReport.xsl' /> </Target> </Project>
You can add namespaces in your code and all that, but you can effectively wildcard the namespace. Try the following XPath idiom.
name() usually works as well, as in:
EDIT: Namespaces are great and i’m not suggesting they’re not important, but wildcarding them comes in handy when cobbling together prototype code, one-off desktop tools, experimenting with XSLT, and so forth. Balance your need for convenience against acceptable risk for the task at hand. FYI, if need be, you can also strip or reassign namespaces.