Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <#
  2. Purges illegal XML characters from XML files in provided folder (and its subfolders).
  3. Encodes out file as UTF8 without BOM.
  4. Peter Tyrrell, Andornot
  5. #>
  6.  
  7. param (
  8. [string]$indir
  9. )
  10.  
  11. $files = ls $indir -filter "*.xml" -recurse
  12. $utf8nobom = new-object System.Text.UTF8Encoding($false) # write UTF8 output without BOM as Java xml parsers choke on it
  13.  
  14.  
  15. foreach ($file in $files) {
  16. $f = (get-content $file.FullName) -replace '[^\u0009\u000a\u000d\u0020-\uD7FF\uE000-\uFFFD]', 'XXX'
  17. [System.IO.File]::WriteAllLines($file.FullName, $f, $utf8nobom)
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement