Line: 13, Position 15: "The 'bar' element is invalid - The value 'd' is invalid according to its datatype '' - The string 'd' is not a valid Integer value." The exception thrown is Line: 7, Position 15: "The 'bar' element is invalid - The value 'b' is invalid according to its datatype '' - The string 'b' is not a valid Integer value." Public static void ValidateAgainstSchema(string XMLSourceDocument, XmlSchemaSet validatingSchemas) XmlSchemaSet schemaSet = new XmlSchemaSet()
I don't see anything wrong with your approach and if I use your code it throws more than one error if there is one, I used your class and the following console application code using System Is there any way I can do what I want? It's obviously not working as is, but is there something obvious I'm missing? Like I said, the first error in an XML document always comes through fine and as expected, but then the HandleValidationError event handler Private IList myValidationErrors = new List() Throw new XmlSchemaValidationException(errorHolder) Īnd the validation handler class is such: If ( > 0)įoreach (String messageItem in handler.MyValidationErrors) Using (XmlReader validatingReader = XmlReader.Create(srStringReader, settings)) StringReader srStringReader = new StringReader(XMLSourceDocument) XmlSchemaValidationFlags.ProcessSchemaLocation XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessIdentit圜onstraints | XmlSchemaValidationFlags.ReportValidationWarnings | Settings.ValidationEventHandler += new ValidationEventHandler(handler.HandleValidationError) Settings.ValidationType = ValidationType.Schema XmlReaderSettings settings = new XmlReaderSettings() ValidationHandler handler = new ValidationHandler() Throw new ArgumentNullException("In ValidateAgainstSchema: No schema loaded.") The code is as follows public static void ValidateAgainstSchema(string XMLSourceDocument, XmlSchemaSet validatingSchemas) I wish to find all the errors so we are able to report all the errorsĪt once, rather than have people submit/fix/resubmit the messages.
I have it validating the XML against the schema correctly, however it always stops at the first validation error. I have an XML string and a Schema loaded up and passed into a function.