Wednesday

linq transformation sample xml xelement.parse used


XElement project = XElement.Parse (@"
<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<PropertyGroup>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProductVersion>9.0.11209</ProductVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include=""ObjectGraph.cs"" />
<Compile Include=""Program.cs"" />
<Compile Include=""Properties\AssemblyInfo.cs"" />
<Compile Include=""Tests\Aggregation.cs"" />
<Compile Include=""Tests\Advanced\RecursiveXml.cs"" />
</ItemGroup>
</Project>");

XNamespace ns = project.Name.Namespace;

var query =
new XElement ("ProjectReport",
from compileItem in project.Elements (ns + "ItemGroup").Elements (ns + "Compile")
let include = compileItem.Attribute ("Include")
where include != null
select new XElement ("File", include.Value)
);

query.Dump();

and results will be:

<ProjectReport>
<File>ObjectGraph.cs</File>
<File>Program.cs</File>
<File>Properties\AssemblyInfo.cs</File>
<File>Tests\Aggregation.cs</File>
<File>Tests\Advanced\RecursiveXml.cs</File>
</ProjectReport>



more...

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...