Skip to content

Instantly share code, notes, and snippets.

@vors
Created March 21, 2015 21:13
Show Gist options
  • Save vors/6a5fb848476f20db6228 to your computer and use it in GitHub Desktop.
Save vors/6a5fb848476f20db6228 to your computer and use it in GitHub Desktop.
PowerShell function to convert any [xml] element to string
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()
}
@janisBerz
Copy link

Indeed! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment