我有大的xml文件(150 000行),每行都有错误,验证过程很长 如何在预定数量的erorrs之后中断验证?
代码示例:
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!!!!
}
}
答案 0 :(得分:2)
这就是例外情况。
throw new Exception("Too many errors, man");
如果您担心会发生不同类型的错误,you can make your own type:
public class TooManyValidationErrorsException : Exception { }
throw new TooManyValidationErrorsException