XmlSchemaCollection.ValidationEventHandler イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlSchemaCollection.ValidationEventHandler イベントの意味・解説 

XmlSchemaCollection.ValidationEventHandler イベント

XDR および XML スキーマ検証エラーに関する情報を受信するためのイベント ハンドラを設定します。

名前空間: System.Xml.Schema
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Public Event ValidationEventHandler As
 ValidationEventHandler
Dim instance As XmlSchemaCollection
Dim handler As ValidationEventHandler

AddHandler instance.ValidationEventHandler, handler
public event ValidationEventHandler ValidationEventHandler
public:
event ValidationEventHandler^ ValidationEventHandler {
    void add (ValidationEventHandler^ value);
    void remove (ValidationEventHandler^ value);
}
/** @event */
public void add_ValidationEventHandler (ValidationEventHandler
 value)

/** @event */
public void remove_ValidationEventHandler (ValidationEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

これらのイベントは、スキーマをコレクションに追加するときに発生します。イベント ハンドラが提供されない場合、XmlSchemaException は、Severity が XmlSeverityType.Error である任意の検証エラーにスローされます。イベント ハンドラを指定するには、コールバック関数を定義し、それを ValidationEventHandler に追加します。

メモ重要 :

XmlSchemaCollection クラスは .NET Framework Version 2.0 では使用されなくなり、XmlSchemaSet クラスに置き換えられました。

使用例使用例

無効な XML スキーマを処理するイベント ハンドラの設定方法の例を次に示します。

Imports System
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
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);
  }  
}
#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();
}
import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Schema.*;

public class Sample
{
    public static void main(String[]
 args)
    {
        //Create the schema collection.
        XmlSchemaCollection xSc = new XmlSchemaCollection();
        //Set an event handler to manage invalid schemas.
        xSc.add_ValidationEventHandler(new ValidationEventHandler(
            ValidationCallBack));
        //Add the schema to the collection.  
        xSc.Add(null, "invalid.xsd");
    } //main

    //Display the schema error information.
    private static void
 ValidationCallBack(Object sender,
        ValidationEventArgs args)
    {
        Console.WriteLine("Invalid XSD schema: " + args.get_Exception().
            get_Message());
    } //ValidationCallBack
} //Sample
import System
import System.IO
import System.Xml
import System.Xml.Schema

public class Sample
{

  public static function
 Main (){

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

    //Set an event handler to manage invalid schemas.
    xsc.add_ValidationEventHandler(ValidationCallBack);

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

  }    

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

}

上の例では、入力として 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSchemaCollection クラス
XmlSchemaCollection メンバ
System.Xml.Schema 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

XmlSchemaCollection.ValidationEventHandler イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlSchemaCollection.ValidationEventHandler イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS