To validate an XML file with an XSD file, use this !
public static XmlDocument ValidateAndLoadXmlDocument(string xmlFilePath, string xsdFilePath)
{
XmlDocument xmlDoc;
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.Schemas.Add(null, xsdFilePath);
xmlSettings.ValidationType = ValidationType.Schema;
XmlReader xmlReader = XmlReader.Create(xmlFilePath, xmlSettings);
xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);
return xmlDoc;
}
Use this for asynchronous validation :
xmlSettings.ValidationEventHandler += new ValidationEventHandler(YourValidationEventHandler);