I am checking an XML file against an xsd schema. So far so good, the code throws an exception in case of failure.
bool isValid = true; List<string> errorList = new List<string>(); try { XmlReaderSettings settings = new XmlReaderSettings(); settings.Schemas.Add(null, schemaFilePath); settings.ValidationType = ValidationType.Schema; XmlDocument document = new XmlDocument(); document.LoadXml(xml); XmlReader rdr = XmlReader.Create(new StringReader(document.InnerXml), settings); while (rdr.Read()) { } } catch (Exception ex) { errorList.Add(ex.Message); isValid = false; } LogErrors(errorList); return isValid;
But I need the code to create a list of all errors found in the check before sending it to my log, and not always show only the first one found.
Any thoughts?
source share