Validating xml visual studio
So far, I've described the steps used to validate XML data with the . From here, it's a simple matter to use to validate the contents of the file (see Listing 3).Begin by declaring variables to hold the path of the XML and XSD schema files, then create an instance of the Xml Reader Settings object and associate a validation event handler callback method to it.So far, you've seen how to perform validation using the standalone XSD schema file through the Xml Reader Settings class.This approach is an excellent way to validate XML data, but it doesn't provide a neat and efficient way of reusing XML schemas.
Use the Validation Event Handler event to define an event handler for receiving the notification about XSD schema validation errors.
This is where the Xml Schema Set class comes into play.
This class not only lets you create a cache of XML schemas, but it also enables you to compile multiple schemas for the same target namespace into a single logical schema.
Next, set the Xsd Validate property to True, which signals the Xml Reader object to validate the XML data as it parses XML data.
By default, you set this property to False so the Xml Reader object doesn't validate the XML data by default.