Created
March 21, 2012 00:02
-
-
Save jstangroome/2142783 to your computer and use it in GitHub Desktop.
Strip elements and attributes added to a TFS 2010 Build Process Template by the designer for a cleaner change history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2.0 | |
[CmdletBinding()] | |
param( | |
[parameter(Mandatory=$true)] | |
[ValidateScript({ $_ | Test-Path -PathType Leaf })] | |
[string] | |
$Path | |
) | |
function New-XmlNamespaceManager ($XmlDocument, $DefaultNamespacePrefix) { | |
$NsMgr = New-Object -TypeName System.Xml.XmlNamespaceManager -ArgumentList $XmlDocument.NameTable | |
$DefaultNamespace = $XmlDocument.DocumentElement.GetAttribute('xmlns') | |
if ($DefaultNamespace -and $DefaultNamespacePrefix) { | |
$NsMgr.AddNamespace($DefaultNamespacePrefix, $DefaultNamespace) | |
} | |
$XmlDocument.DocumentElement.Attributes | | |
Where-Object { $_.Prefix -eq 'xmlns' } | | |
ForEach-Object { | |
$NsMgr.AddNamespace($_.LocalName, $_.Value) | |
} | |
return ,$NsMgr # unary comma wraps $NsMgr so it isn't unrolled | |
} | |
$ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version Latest | |
$x = [xml](Get-Content -Path $Path) | |
$nsmgr = New-XmlNamespaceManager -XmlDocument $x | |
'http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation', | |
'clr-namespace:System.Activities.Debugger;assembly=System.Activities' | | |
ForEach-Object { | |
$Namespace = $_ | |
$prefix = $nsmgr.LookupPrefix($namespace) | |
if ($prefix) { | |
$x.SelectNodes("//$($prefix):*", $nsmgr) | | |
ForEach-Object { | |
$_.ParentNode.RemoveChild($_) | Out-Null | |
} | |
$x.SelectNodes("//@*[namespace-uri()='$namespace']") | | |
ForEach-Object { | |
$_.OwnerElement.RemoveAttributeNode($_) | Out-Null | |
} | |
} | |
} | |
$x.Save($Path + '.clean') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment