Question

I have big xml file (150 000 rows), and each row has an error, validation process is very long How to break validation after a predetermined number of erorrs?

Code sample:

MaxValidationErrorCount = 100;

    ....
doc.Validate(ValidationHandler);

....

private void ValidationHandler(object sender, System.Xml.Schema.ValidationEventArgs e)
{
    if (e.Severity == System.Xml.Schema.XmlSeverityType.Error)
    {
        CurrValidationErrorCount++;
        _validationErrors += e.Message + Environment.NewLine;

        if (CurrValidationErrorCount >= MaxValidationErrorCount)
            DOBREAKVALIDATIONHERE!!!!
    }


}
Was it helpful?

Solution

That's what Exceptions are for.

throw new Exception("Too many errors, man");

And if you fear different kinds of errors can occur, you can make your own type:

public class TooManyValidationErrorsException : Exception { }

throw new TooManyValidationErrorsException
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top