Trying to perform a simple analysis of an XML document. What is the easiest way to pull two PropertyGroups below?
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1
</PropertyGroup>
<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2
</PropertyGroup>
</Project>
I am trying to use XElement.Elements (XName), but for this I need a PropertyGroup prefix using xmlns. The problem is that I am not interested in the namespace, and if that changes in the future, I will still like all PropertyGroups.
var xml = XElement.Load(fileNameWithPath);
var nameSpace = xml.GetDefaultNamespace();
var propertyGroups= xml.Elements(nameSpace + "PropertyGroup");
Can you improve this code so that I donβt need to add a name called Space? I know that I can essentially just override the Elements method, but I was hoping there was a way to pass a wildcard namespace?
Thank,
Gavin
source
share