XmlSchemaException クラス

定義

スキーマ例外に関する詳細情報を返します。

public ref class XmlSchemaException : SystemException
public class XmlSchemaException : SystemException
[System.Serializable]
public class XmlSchemaException : SystemException
type XmlSchemaException = class
    inherit SystemException
[<System.Serializable>]
type XmlSchemaException = class
    inherit SystemException
Public Class XmlSchemaException
Inherits SystemException
継承
XmlSchemaException
派生
属性

XmlSchemaException クラスの使用例を次に示します。

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

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

class ValidXsd
{
public:

    static void Main()
    {
        FileStream^ fs;
        XmlSchema^ schema;

        try
        {
            fs = gcnew FileStream("example.xsd", FileMode::Open);
            schema = XmlSchema::Read(fs, gcnew ValidationEventHandler(ShowCompileError));

            XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
            schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ShowCompileError);
            schemaSet->Add(schema);
            schemaSet->Compile();

            XmlSchema^ compiledSchema;

            for each (XmlSchema^ schema1 in schemaSet->Schemas())
            {
                compiledSchema = schema1;
            }

            schema = compiledSchema;

            if (schema->IsCompiled)
            {
                // Schema is successfully compiled. 
                // Do something with it here.

            }
        }
        catch (XmlSchemaException^ e)
        {
            Console::WriteLine("LineNumber = {0}", e->LineNumber);
            Console::WriteLine("LinePosition = {0}", e->LinePosition);
            Console::WriteLine("Message = {0}", e->Message);
        }

    }

    static void ShowCompileError(Object^ sender, ValidationEventArgs^ e)
    {
        Console::WriteLine("Validation Error: {0}", e->Message);
    }
};

int main()
{
    ValidXsd::Main();
    Console::ReadLine();
    return 0;
};
using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class ValidXSD
{
    public static int Main()
    {

        FileStream fs;
        XmlSchema schema;
        try
        {
            fs = new FileStream("example.xsd", FileMode.Open);
            schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));

            XmlSchemaSet schemaSet = new XmlSchemaSet();
            schemaSet.ValidationEventHandler += new ValidationEventHandler(ShowCompileError);
            schemaSet.Add(schema);
            schemaSet.Compile();

            XmlSchema compiledSchema = null;

            foreach (XmlSchema schema1 in schemaSet.Schemas())
            {
                compiledSchema = schema1;
            }

            schema = compiledSchema;

            if (schema.IsCompiled)
            {
                // Schema is successfully compiled.
                // Do something with it here.
            }
            return 0;
        }
        catch (XmlSchemaException e)
        {
            Console.WriteLine("LineNumber = {0}", e.LineNumber);
            Console.WriteLine("LinePosition = {0}", e.LinePosition);
            Console.WriteLine("Message = {0}", e.Message);
            return -1;
        }
    }

    private static void ShowCompileError(object sender, ValidationEventArgs e)
    {
        Console.WriteLine("Validation Error: {0}", e.Message);
    }
}
Option Strict On
Option Explicit On

Imports System.Xml
Imports System.Xml.Schema
Imports System.IO

Public Class ValidXSD
    Public Shared Sub Main()
        Dim fs As FileStream
        Dim schema As XmlSchema
        Try
            fs = New FileStream("example.xsd", FileMode.Open)
            schema = XmlSchema.Read(fs, New ValidationEventHandler(AddressOf ShowCompileError))

            Dim schemaSet As New XmlSchemaSet()
            AddHandler schemaSet.ValidationEventHandler, AddressOf ShowCompileError

            schemaSet.Add(schema)
            schemaSet.Compile()

            Dim compiledSchema As XmlSchema = Nothing

            For Each schema1 As XmlSchema In schemaSet.Schemas()
                compiledSchema = schema1
            Next

            schema = compiledSchema

            If schema.IsCompiled Then
                ' Schema is successfully compiled. 
                ' Do something with it here.
            End If

        Catch e As XmlSchemaException
            Console.WriteLine("LineNumber = {0}", e.LineNumber)
            Console.WriteLine("LinePosition = {0}", e.LinePosition)
            Console.WriteLine("Message = {0}", e.Message)
            Console.WriteLine("Source = {0}", e.Source)

        End Try
    End Sub


    Private Shared Sub ShowCompileError(ByVal sender As Object, ByVal e As ValidationEventArgs)
        Console.WriteLine("Validation Error: {0}", e.Message)
    End Sub
End Class

注釈

重要

この XmlSchemaException クラスには、信頼されていないシナリオでは公開すべきでない機密情報が含まれている場合があります。 たとえば、このプロパティは SourceUri 、例外の原因となったスキーマ ファイルへの URI パスを返します。 このプロパティは SourceUri 、信頼されていないシナリオでは公開しないでください。 この機密情報が信頼されていないシナリオで公開されないように、例外を適切に処理する必要があります。

コンストラクター

XmlSchemaException()

XmlSchemaException クラスの新しいインスタンスを初期化します。

XmlSchemaException(SerializationInfo, StreamingContext)

XmlSchemaException のすべてのプロパティを含む指定した SerializationInfo 情報および StreamingContext 情報を使用して、新しい XmlSchemaException オブジェクトを構築します。

XmlSchemaException(String)

XmlSchemaException クラスの新しいインスタンスを、指定された例外メッセージを使用して初期化します。

XmlSchemaException(String, Exception)

XmlSchemaException クラスの新しいインスタンスを、例外メッセージおよびこの例外が発生する原因になった元の Exception オブジェクトを指定して初期化します。

XmlSchemaException(String, Exception, Int32, Int32)

XmlSchemaException クラスの新しいインスタンスを、例外メッセージ、この例外が発生する原因になった Exception オブジェクト、XML の行番号、および XML の行位置を指定して初期化します。

プロパティ

Data

例外に関する追加のユーザー定義情報を提供する、キーと値のペアのコレクションを取得します。

(継承元 Exception)
HelpLink

この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。

(継承元 Exception)
HResult

特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。

(継承元 Exception)
InnerException

現在の例外の原因となる Exception インスタンスを取得します。

(継承元 Exception)
LineNumber

エラーの発生場所を示す行番号を取得します。

LinePosition

エラーの発生場所を示す行の位置を取得します。

Message

この例外のエラー状態の説明を取得します。

Source

エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。

(継承元 Exception)
SourceSchemaObject

XmlSchemaObject を生成した XmlSchemaException

SourceUri

例外の発生原因となったスキーマの URI (Uniform Resource Identifier) 位置を取得します。

StackTrace

呼び出し履歴で直前のフレームの文字列形式を取得します。

(継承元 Exception)
TargetSite

現在の例外がスローされたメソッドを取得します。

(継承元 Exception)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetBaseException()

派生クラスでオーバーライドされた場合、それ以後に発生する 1 つ以上の例外の根本原因である Exception を返します。

(継承元 Exception)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetObjectData(SerializationInfo, StreamingContext)

すべての XmlSchemaException プロパティを、指定した SerializationInfoStreamingContext クラスにストリーム転送します。

GetType()

現在のインスタンスのランタイム型を取得します。

(継承元 Exception)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在の例外の文字列形式を作成して返します。

(継承元 Exception)

events

SerializeObjectState
互換性のために残されています。

例外がシリアル化され、例外に関するシリアル化されたデータを含む例外状態オブジェクトが作成されたときに発生します。

(継承元 Exception)

適用対象