.NET 2.0: XmlDocument and Validation
Here is what I worked up based on the scanty help files available with VS 2005 Beta 2:
XmlSchemaSet schemaSet =new XmlSchemaSet(); schemaSet.Add("<nameSpace>", "<path to schema file>"); XmlDocument sessionDocument =new XmlDocument(); sessionDocument.Schemas = schemaSet; sessionDocument.Load("<path to xml file>"); ValidationEventHandler eventHandler =new ValidationEventHandler(HandleValidationError); |
If I alter my XML file so that it violates the schema I'm trying to validate it against here, it does not fire the delegate methodHandleValidationError(). With other objects, etc. it is allowed to call methods similar to Validate (that accept a delegate like this) without the delegate parameter and it will just throw an exception. This method does not allow that, and this stinks as I can think of no good way to have code following the Validate call not execute if the document does not validate.
Any suggestions welcome. Thanks.

