1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
private bool validationSuccess;
private List<string> errorsInXml;
private XmlReaderSettings settings = new XmlReaderSettings();
private bool validateXML(string path)
{
validationSuccess = true;
errorsInXml = new List<string>();
try
{
settings.Schemas.Add(null, "../../CheckXml.xsd");
settings.ValidationType = ValidationType.Schema;
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader URI_XMlreader = XmlReader.Create(path, settings);
while (URI_XMlreader.Read()) { }
}
catch
{
return false;
}
return validationSuccess;
}
private void ValidationCallBack(object sender, ValidationEventArgs args)
{
validationSuccess = false;
errorsInXml.Add(args.Message);
XmlSchemaException ex = args.Exception;
string message = string.Format(ex.Message + Environment.NewLine + "Ligne n° " + ex.LineNumber);
MessageBox.Show(message);
} |
Partager