XmlSchemaException 類別

定義

回傳關於結構例外的詳細資訊。

public ref class XmlSchemaException : SystemException
[System.Serializable]
public class XmlSchemaException : SystemException
public class XmlSchemaException : SystemException
[<System.Serializable>]
type XmlSchemaException = class
    inherit SystemException
type XmlSchemaException = class
    inherit SystemException
Public Class XmlSchemaException
Inherits SystemException
繼承
XmlSchemaException
衍生
屬性

範例

以下範例展示了該 XmlSchemaException 類別的使用情況。

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

備註

Important

XmlSchemaException 類別可能包含敏感資訊,不應在不可信情境中暴露。 例如,屬性 SourceUri 會回傳導致異常的結構檔案的 URI 路徑。 屬性 SourceUri 不應在不受信任的情境中公開。 應正確處理例外狀況,如此一來,此敏感性資訊就不會在不受信任的案例中公開。

建構函式

名稱 Description
XmlSchemaException()

初始化 XmlSchemaException 類別的新執行個體。

XmlSchemaException(SerializationInfo, StreamingContext)

構造 XmlSchemaException 一個包含 SerializationInfoStreamingContextXmlSchemaException所有屬性的資訊與新物件。

XmlSchemaException(String, Exception, Int32, Int32)

初始化一個新的類別實例 XmlSchemaException ,並指定例外訊息,並指定導致此例外的原始 Exception 物件、行號與行位置。

XmlSchemaException(String, Exception)

初始化該類別的新實例 XmlSchemaException ,並指定例外訊息及導致此例外的原始 Exception 物件。

XmlSchemaException(String)

初始化類別的新實例 XmlSchemaException ,並指定例外訊息。

屬性

名稱 Description
Data

取得索引鍵/值組的集合,提供例外狀況的其他使用者定義資訊。

(繼承來源 Exception)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。

(繼承來源 Exception)
HResult

取得或設定 HRESULT,這是指派給特定例外狀況的編碼數值。

(繼承來源 Exception)
InnerException

會取得 Exception 造成目前例外的實例。

(繼承來源 Exception)
LineNumber

取得錯誤發生位置的行號。

LinePosition

取得錯誤發生位置的行位。

Message

取得此例外錯誤條件的描述。

Source

取得或設定造成錯誤之應用程式或物件的名稱。

(繼承來源 Exception)
SourceSchemaObject

XmlSchemaObject 產生了 XmlSchemaException

SourceUri

取得導致異常的結構的統一資源識別碼(URI)位置。

StackTrace

取得呼叫堆疊上即時框架的字串表示。

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。

(繼承來源 Exception)

方法

名稱 Description
Equals(Object)

判斷指定的 物件是否等於目前的物件。

(繼承來源 Object)
GetBaseException()

當在派生類別中被覆寫時,回傳 Exception 是一個或多個後續例外的根因。

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)

將所有 XmlSchemaException 屬性串流到 SerializationInfo 給定 StreamingContext的類別中。

GetType()

取得目前實例的運行時間類型。

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。

(繼承來源 Exception)

事件

名稱 Description
SerializeObjectState

發生於例外狀況串行化以建立例外狀況狀態物件,其中包含例外狀況的串行化數據。

(繼承來源 Exception)

適用於