Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. tylerd revised this gist Mar 28, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Remove-WorkflowPresentation.ps1
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ $x = [xml](Get-Content -Path $Path)
    $nsmgr = New-XmlNamespaceManager -XmlDocument $x

    'http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation',
    'http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation',
    'clr-namespace:System.Activities.Debugger;assembly=System.Activities' |
    ForEach-Object {
    $Namespace = $_
    @@ -43,4 +44,4 @@ $nsmgr = New-XmlNamespaceManager -XmlDocument $x
    }
    }
    }
    $x.Save($Path + '.clean')
    $x.Save($Path + '.clean')
  2. @jstangroome jstangroome created this gist Mar 21, 2012.
    46 changes: 46 additions & 0 deletions Remove-WorkflowPresentation.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #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')