Possible Duplicate:
Xml validation using XSD schema
I have generated some XML using some C#. I need to see if that XML validates against an XSD file. Is there a way to do this in C#? If so, how do I do this?
Possible Duplicate:
Xml validation using XSD schema
I have generated some XML using some C#. I need to see if that XML validates against an XSD file. Is there a way to do this in C#? If so, how do I do this?
See this question:
Xml validation using XSD schema
It shows that all you need to do is set the right option when creating your XmlReader:
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, xsdFilePath);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);
var reader = XmlReader.Create(source, settings);
You will now get information on validation errors in settings_ValidationEventHandler
and the document load will be aborted if required.