Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Purges illegal XML characters from XML files in provided folder (and its subfolders).
- Encodes out file as UTF8 without BOM.
- Peter Tyrrell, Andornot
- #>
- param (
- [string]$indir
- )
- $files = ls $indir -filter "*.xml" -recurse
- $utf8nobom = new-object System.Text.UTF8Encoding($false) # write UTF8 output without BOM as Java xml parsers choke on it
- foreach ($file in $files) {
- $f = (get-content $file.FullName) -replace '[^\u0009\u000a\u000d\u0020-\uD7FF\uE000-\uFFFD]', 'XXX'
- [System.IO.File]::WriteAllLines($file.FullName, $f, $utf8nobom)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement