Data/Xml/Format-Xml.ps1
function Format-Xml { <# .SYNOPSIS Format the incoming object as the text of an XML document. #> param( ## Text of an XML document. [Parameter(ValueFromPipeline = $true)] [string[]]$Text ) begin { $data = New-Object System.Collections.ArrayList } process { [void] $data.Add($Text -join "`n") } end { $doc = New-Object System.Xml.XmlDataDocument $doc.LoadXml($data -join "`n") $sw = New-Object System.Io.Stringwriter $writer = New-Object System.Xml.XmlTextWriter($sw) $writer.Formatting = [System.Xml.Formatting]::Indented $doc.WriteContentTo($writer) $sw.ToString() } } |