XmlSchemaCollection.ValidationEventHandler 이벤트

정의

XDR 및 XML 스키마 유효성 검사 오류에 대한 정보를 받는 이벤트 처리기를 설정합니다.

public:
 event System::Xml::Schema::ValidationEventHandler ^ ValidationEventHandler;
public event System.Xml.Schema.ValidationEventHandler ValidationEventHandler;
member this.ValidationEventHandler : System.Xml.Schema.ValidationEventHandler 

이벤트 유형

예제

다음 예제에서는 잘못된 XML 스키마를 처리하도록 이벤트 처리기를 설정하는 방법을 보여 줍니다.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Schema;

public ref class Sample
{
private:
   //Display the schema error information.
   static void ValidationCallBack( Object^ sender, ValidationEventArgs^ args )
   {
      Console::WriteLine( "Invalid XSD schema: {0}", args->Exception->Message );
   }

public:
   static void main()
   {
      // Create the schema collection.
      XmlSchemaCollection^ xsc = gcnew XmlSchemaCollection;

      //Set an event handler to manage invalid schemas.
      xsc->ValidationEventHandler += gcnew ValidationEventHandler( Sample::ValidationCallBack );

      //Add the schema to the collection.  
      xsc->Add( nullptr, "invalid.xsd" );
   }
};

int main()
{
   Sample::main();
}
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);
  }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema

public class Sample

  public shared sub Main ()
 
    'Create the schema collection.
    Dim xsc as XmlSchemaCollection = new XmlSchemaCollection()

    'Set an event handler to manage invalid schemas.
    AddHandler xsc.ValidationEventHandler, AddressOf ValidationCallBack

    'Add the schema to the collection.  
    xsc.Add(nothing, "invalid.xsd")

  end sub

  'Display the schema error information.
  Private shared sub ValidationCallBack (sender as object, args as ValidationEventArgs) 
     Console.WriteLine("Invalid XSD schema: " + args.Exception.Message)
  end sub

end class

앞의 예제에서는 파일을 invalid.xsd 입력으로 사용합니다.

<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema' >
 <xsd:complexType name="personName">
        <xsd:sequence>
            <xsd:element name="title" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="forename" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="surname"/>
        </xsd:sequence>
    </xsd:complexType>

   <xsd:complexType name="simpleName">
        <xsd:complexContent>
            <xsd:restriction base="personName">
                <xsd:sequence>
                    <xsd:element name="title" minOccurs="0" maxOccurs="0"/>
                    <xsd:element name="firstname" minOccurs="1" maxOccurs="1"/>
                    <xsd:element name="surname"/>
                </xsd:sequence>
            </xsd:restriction>
        </xsd:complexContent>
    </xsd:complexType>

</xsd:schema>

설명

이러한 이벤트는 스키마가 컬렉션에 추가되면 발생합니다. 이벤트 처리기가 제공되지 XmlSchemaException 않으면 가 인 유효성 검사 오류에 대해 이 Severity throw됩니다 XmlSeverityType.Error. 이벤트 처리기를 지정하려면 콜백 함수를 정의하고 에 ValidationEventHandler추가합니다.

중요

클래스는 XmlSchemaCollection .NET Framework 버전 2.0에서 사용되지 않으며 클래스로 XmlSchemaSet 대체되었습니다.

적용 대상