jeudi 10 janvier 2013

Reading xml from PowerShell is really easy !

It is amusing to see how simple we can read xml node values from powershell :

Here is a peace of xml file

<?xml version="1.0" standalone="yes"?>

PowerShell converts XML elements to properties on .NET objects without the need to write any parsing code !!
$coverageFileXml = “C:\temp\myCoverageInfo.xml”
[xml]$xml = (get-content $coverageFileXml)
[int]$BlocksCovered = $xml.CoverageDSPriv.Module.BlocksCovered
[int]$BlocksNotCovered = $xml.CoverageDSPriv.Module.BlocksNotCovered
[int]$TotalBlocks = $BlocksCovered + $BlocksNotCovered
$CoveragePercent = $BlocksCovered * 100 / $TotalBlocks
$CoveragePercent2Decimals =  "{0:N2}" -f $CoveragePercent
Write-Host "Coverage is $CoveragePercent2Decimals %" 

è                         Output is   :   Coverage is 48.62 %

--> Share/Bookmark

Aucun commentaire: