XmlSchemaException XmlSchemaException XmlSchemaException XmlSchemaException Class

定义

返回关于架构异常的详细信息。Returns detailed information about the schema exception.

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

示例

下面的示例演示如何使用XmlSchemaException类。The following example shows the use of the XmlSchemaException class.

#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类可能包含不应在不受信任的方案中公开的敏感信息。The XmlSchemaException class may contain sensitive information that should not be exposed in untrusted scenarios. 例如, SourceUri属性返回引发异常的架构文件的 URI 路径。For example, the SourceUri property returns the URI path to the schema file that caused the exception. SourceUri应在不受信任的方案中公开属性。The SourceUri property should not be exposed in untrusted scenarios. 应正确处理异常,以便不受信任的情况下不公开此敏感信息。Exceptions should be properly handled so that this sensitive information is not exposed in untrusted scenarios.

构造函数

XmlSchemaException() XmlSchemaException() XmlSchemaException() XmlSchemaException()

初始化 XmlSchemaException 类的新实例。Initializes a new instance of the XmlSchemaException class.

XmlSchemaException(SerializationInfo, StreamingContext) XmlSchemaException(SerializationInfo, StreamingContext) XmlSchemaException(SerializationInfo, StreamingContext) XmlSchemaException(SerializationInfo, StreamingContext)

用包含 XmlSchemaException 所有属性的给定的 SerializationInfoStreamingContext 信息构造新的 XmlSchemaException 对象。Constructs a new XmlSchemaException object with the given SerializationInfo and StreamingContext information that contains all the properties of the XmlSchemaException.

XmlSchemaException(String) XmlSchemaException(String) XmlSchemaException(String) XmlSchemaException(String)

用指定的异常消息初始化 XmlSchemaException 类的新实例。Initializes a new instance of the XmlSchemaException class with the exception message specified.

XmlSchemaException(String, Exception) XmlSchemaException(String, Exception) XmlSchemaException(String, Exception) XmlSchemaException(String, Exception)

使用异常消息和导致此指定的异常的原始 XmlSchemaException 对象初始化 Exception 类的新实例。Initializes a new instance of the XmlSchemaException class with the exception message and original Exception object that caused this exception specified.

XmlSchemaException(String, Exception, Int32, Int32) XmlSchemaException(String, Exception, Int32, Int32) XmlSchemaException(String, Exception, Int32, Int32) XmlSchemaException(String, Exception, Int32, Int32)

使用指定的异常消息和导致此指定异常的原始 XmlSchemaException 对象、XML 的行号和行位置初始化 Exception 类的新实例。Initializes a new instance of the XmlSchemaException class with the exception message specified, and the original Exception object, line number, and line position of the XML that cause this exception specified.

属性

Data Data Data Data

获取提供有关异常的其他用户定义信息的键/值对集合。Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

获取或设置指向与此异常关联的帮助文件链接。Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

获取或设置 HRESULT(一个分配给特定异常的编码数字值)。Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

获取导致当前异常的 Exception 实例。Gets the Exception instance that caused the current exception.

(Inherited from Exception)
LineNumber LineNumber LineNumber LineNumber

获取指示错误发生位置的行号。Gets the line number indicating where the error occurred.

LinePosition LinePosition LinePosition LinePosition

获取指示错误发生位置的行位置。Gets the line position indicating where the error occurred.

Message Message Message Message

获取此异常的错误情况的说明。Gets the description of the error condition of this exception.

Source Source Source Source

获取或设置导致错误的应用程序或对象的名称。Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
SourceSchemaObject SourceSchemaObject SourceSchemaObject SourceSchemaObject

生成 XmlSchemaObjectXmlSchemaExceptionThe XmlSchemaObject that produced the XmlSchemaException.

SourceUri SourceUri SourceUri SourceUri

获取导致此异常的架构的统一资源标识符 (URI) 位置。Gets the Uniform Resource Identifier (URI) location of the schema that caused the exception.

StackTrace StackTrace StackTrace StackTrace

获取调用堆栈上的即时框架字符串表示形式。Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

获取引发当前异常的方法。Gets the method that throws the current exception.

(Inherited from Exception)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

对于给定的 XmlSchemaException,将所有的 SerializationInfo 属性流式写入 StreamingContext 类。Streams all the XmlSchemaException properties into the SerializationInfo class for the given StreamingContext.

GetType() GetType() GetType() GetType()

获取当前实例的运行时类型。Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

创建并返回当前异常的字符串表示形式。Creates and returns a string representation of the current exception.

(Inherited from Exception)

事件

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

当异常被序列化用来创建包含有关该异常的徐列出数据的异常状态对象时会出现该问题。Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

适用于