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)

以指定的 XmlSchemaExceptionSerializationInfo 資訊建構包含 StreamingContext 所有屬性的新 XmlSchemaException 物件。

XmlSchemaException(String)

使用指定的例外狀況訊息,初始化 XmlSchemaException 類別的新執行個體。

XmlSchemaException(String, Exception)

使用例外狀況訊息和導致這個指定之例外狀況的原始 XmlSchemaException 物件,初始化 Exception 類別的新執行個體。

XmlSchemaException(String, Exception, Int32, Int32)

使用指定的例外狀況訊息,以及導致這個指定之例外狀況的原始 XmlSchemaException 物件、XML 中的行號和行位置,初始化 Exception 類別的新執行個體。

屬性

Data

取得鍵值組的集合,這些鍵值組會提供關於例外狀況的其他使用者定義資訊。

(繼承來源 Exception)
HelpLink

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

(繼承來源 Exception)
HResult

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

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。

(繼承來源 Exception)
LineNumber

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

LinePosition

取得行位置,指出發生錯誤的位置。

Message

取得這個例外狀況之錯誤條件的描述。

Source

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

(繼承來源 Exception)
SourceSchemaObject

產生 XmlSchemaObjectXmlSchemaException

SourceUri

取得導致該例外狀況之結構描述的統一資源識別元 (URI) 位置。

StackTrace

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

(繼承來源 Exception)
TargetSite

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

(繼承來源 Exception)

方法

Equals(Object)

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

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 Exception

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。

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

將所有 XmlSchemaException 屬性資料流至指定之 SerializationInfoStreamingContext 類別。

GetType()

取得目前執行個體的執行階段類型。

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Exception)

事件

SerializeObjectState
已淘汰.

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。

(繼承來源 Exception)

適用於