Created
March 21, 2015 21:13
-
-
Save vors/6a5fb848476f20db6228 to your computer and use it in GitHub Desktop.
PowerShell function to convert any [xml] element to string
This file contains hidden or 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
function Convert-XmlElementToString | |
{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true)] | |
$xml | |
) | |
$sw = [System.IO.StringWriter]::new() | |
$xmlSettings = [System.Xml.XmlWriterSettings]::new() | |
$xmlSettings.ConformanceLevel = [System.Xml.ConformanceLevel]::Fragment | |
$xmlSettings.Indent = $true | |
$xw = [System.Xml.XmlWriter]::Create($sw, $xmlSettings) | |
$xml.WriteTo($xw) | |
$xw.Close() | |
return $sw.ToString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this.