ValidationEventHandler Event
Collapse the table of content
Expand the table of content

XmlSchemaCollection.ValidationEventHandler Event

Use BaseTrue

Sets an event handler for receiving information about the XDR and XML schema validation errors.

Namespace:   System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

public event ValidationEventHandler ValidationEventHandler

These events occur when the schemas are added to the collection. If an event handler is not provided, an XmlSchemaException is thrown on any validation errors where the Severity is XmlSeverityType.Error. To specify an event handler, define a callback function and add it to the ValidationEventHandler.


The XmlSchemaCollection class is obsolete in the .NET Framework version 2.0 and has been replaced by the XmlSchemaSet class.

The following example shows how to set an event handler to handle invalid XML Schemas.

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Sample

  public static void Main (){

    //Create the schema collection.
    XmlSchemaCollection xsc = new XmlSchemaCollection();

    //Set an event handler to manage invalid schemas.
    xsc.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

    //Add the schema to the collection.  
    xsc.Add(null, "invalid.xsd");


  //Display the schema error information.
  private static void ValidationCallBack (object sender, ValidationEventArgs args){
     Console.WriteLine("Invalid XSD schema: " + args.Exception.Message);

The preceding example uses the file invalid.xsd as input.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft