-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathConvertFrom-EscapedXml.ps1
More file actions
38 lines (32 loc) · 988 Bytes
/
ConvertFrom-EscapedXml.ps1
File metadata and controls
38 lines (32 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.SYNOPSIS
Parse escaped XML into XML and serialize it.
.INPUTS
System.String, some escaped XML.
.FUNCTIONALITY
XML
.OUTPUTS
System.String, the XML parsed and serialized.
.EXAMPLE
ConvertFrom-EscapedXml.ps1 '<a href="http://example.org">link</a>'
<a href="http://example.org">link</a>
#>
#Requires -Version 2
[CmdletBinding()][OutputType([string])] Param(
# The escaped XML text.
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)][string] $EscapedXml,
# Outputs the XML without indentation.
[Alias('NoIndent')][switch] $Compress
)
Process
{
[xml] $xml = [Net.WebUtility]::HtmlDecode($EscapedXml)
$sw = New-Object IO.StringWriter
[Xml.XmlWriterSettings] $cfg = New-Object Xml.XmlWriterSettings -Property @{ Indent = !$Compress; OmitXmlDeclaration = $true }
[Xml.XmlWriter] $xo = [Xml.XmlWriter]::Create($sw, $cfg)
$xml.WriteTo($xo)
$xo.Dispose()
$out = $sw.ToString()
$sw.Dispose()
return $out
}