Skip to content

Commit 16983fb

Browse files
author
Markus Fleschutz
committed
Updated check-xml-file.ps1 and check-xml-files.ps1
1 parent d9c784f commit 16983fb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

scripts/check-xml-file.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ try {
2727
$ReaderSettings.ValidationType = [System.Xml.ValidationType]::Schema
2828
$ReaderSettings.ValidationFlags = [System.Xml.Schema.XmlSchemaValidationFlags]::ProcessInlineSchema -bor [System.Xml.Schema.XmlSchemaValidationFlags]::ProcessSchemaLocation
2929
$ReaderSettings.add_ValidationEventHandler({ $script:ErrorCount++ })
30+
$ReaderSettings.DtdProcessing = [System.Xml.DtdProcessing]::Parse
3031
$Reader = [System.Xml.XmlReader]::Create($XmlFile.FullName, $ReaderSettings)
3132
while ($Reader.Read()) { }
3233
$Reader.Close()

scripts/check-xml-files.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
.SYNOPSIS
33
Checks all XML files in a directory tree
44
.DESCRIPTION
5-
This PowerShell script verifies each XML file (with suffix .xml) in the given directory tree for validity.
5+
This PowerShell script verifies any XML file (with suffix .xml) in the given directory tree for validity.
66
.PARAMETER path
77
Specifies the path to the directory tree (current working dir by default)
88
.EXAMPLE
99
PS> ./check-xml-files.ps1 C:\Windows
1010
...
11-
✔️ Checked 3387 XML files within 📂C:\Windows in 174 sec
11+
✔️ Checked 3387 XML files (2462 invalid, 925 valid) within 📂C:\Windows in 116 sec
1212
.LINK
1313
https://github.com/fleschutz/PowerShell
1414
.NOTES
@@ -19,19 +19,19 @@ param([string]$path = "$PWD")
1919

2020
try {
2121
$stopWatch = [system.diagnostics.stopwatch]::startNew()
22-
2322
$path = Resolve-Path "$path"
24-
[int]$numXmlFiles = 0
23+
Write-Progress "Scanning any XML file within $path..."
24+
[int]$valid = [int]$invalid = 0
2525

26-
Write-Progress "Scanning all XML files within $path..."
2726
Get-ChildItem -path "$path" -attributes !Directory -recurse -force | Where-Object { $_.Name -like "*.xml" } | Foreach-Object {
2827
& $PSScriptRoot/check-xml-file.ps1 "$($_.FullName)"
29-
$numXmlFiles++
28+
if ($lastExitCode -eq 0) { $valid++ } else { $invalid++ }
3029
}
3130
Write-Progress -completed "Done."
3231

32+
[int]$total = $valid + $invalid
3333
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
34-
"✔️ Checked $numXmlFiles XML files within 📂$path in $elapsed sec"
34+
"✔️ Checked $total XML files ($invalid invalid, $valid valid) within 📂$path in $elapsed sec"
3535
exit 0 # success
3636
} catch {
3737
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

0 commit comments

Comments
 (0)