Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active August 29, 2015 14:11
Show Gist options
  • Save IISResetMe/6f4de981c9e179af699a to your computer and use it in GitHub Desktop.
Save IISResetMe/6f4de981c9e179af699a to your computer and use it in GitHub Desktop.
Sanitizes your XML input!
function Repair-XmlString
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$inXML
)
# Match all characters that does NOT belong in an XML document
$rPattern = "[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000\x10FFFF]"
# Replace said characters with [String]::Empty and return
return [System.Text.RegularExpressions.Regex]::Replace($inXML,$rPattern,"")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment