tags:

views:

306

answers:

1

Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function gets a ValidationEventArgs parameter which in turn has an Exception property of the type XmlSchemaException. Whew!

My current code looks like this:

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

doc.Validate(onValidationError);

Is there some other method I'm overlooking which simply throws the XmlSchemaException if validation fails (warnings ignored entirely)?

+2  A: 

Because the Validate method takes the ValidationEventHandler delegate, it is left up to the developer to decide what to do with the excpetion. What you are doing is correct.

Micah