As a part of my development I'd like to be able to validate an entire folder's worth of XML files against a single XSD file. A PowerShell function seems like a good candidate for this as I can then just pipe a list of files to it like so: dir *.xml | Validate-Xml -Schema .\MySchema.xsd
I've considered porting C# code from the Validating an Xml against Referenced XSD in C# question, but I don't know how to Add handlers in PowerShell.
Best Answer
I want to comment that the script in current accepted answer doesn't validate errors about incorrect orders of elements of
xs:sequence
. For example: test.xmltest.xsd
I wrote another version that can report this error:
PS C:\temp\lab-xml-validation> dir test.xml | Test-XmlFile test.xsd