문제

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!!!!
    }


}
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top