0

I am looking for an as-simple-as-possible .NET way to validate an XML file against an XSD file, like so:

validator.IsValid(xmlFile, xsdFile)

I've found a few questions (and answers) on stackoverflow but they all require a callback function. I am aiming for a oneliner since I'd like to execute this in a PowerShell:

$validator = new-object SomeValidator
$validator.IsValid(xmlFile, xsdFile)

1 Answer 1

1

Grab the PowerShell Community Extensions and use the Test-Xml cmdlet. This cmdlet not only tests for well formedness, it can also validate against a schema. Be sure to grab the 2.1 (or 3.0) beta as the 2.0 production version has a bug with schema validation. Here's an example:

Test-Xml $xmlfile -Schema $xsdFile

Not the answer you're looking for? Browse other questions tagged or ask your own question.