如何在XML Schema验证错误上引发XmlSchemaException?

时间:2020-03-06 14:57:27  来源:igfitidea点击:

在XmlDocument上调用" Validate()"需要传入" ValidationEventHandler"委托。该事件函数获得一个" ValidationEventArgs"参数,该参数又具有" XmlSchemaException"类型的" Exception"属性。 ew!

我当前的代码如下所示:

ValidationEventHandler onValidationError = delegate(object sender,
    ValidationEventArgs args)
{
    throw(args.Exception);
}

doc.Validate(onValidationError);

如果验证失败(警告完全被忽略),我还有其他方法可以忽略吗?

解决方案

因为Validate方法采用ValidationEventHandler委托,所以它由开发人员决定如何处理该排他。你在做什么是对的。