This documentation is archived and is not being maintained.

XmlSchemaException Class

Returns detailed information about the schema exception.

For a list of all members of this type, see XmlSchemaException Members.

System.Object
   System.Exception
      System.SystemException
         System.Xml.Schema.XmlSchemaException

[Visual Basic]
<Serializable>
Public Class XmlSchemaException
   Inherits SystemException
[C#]
[Serializable]
public class XmlSchemaException : SystemException
[C++]
[Serializable]
public __gc class XmlSchemaException : public SystemException
[JScript]
public
   Serializable
class XmlSchemaException extends SystemException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Example

[Visual Basic, C#, C++] The following example shows the use of the XmlSchemaException class.

[Visual Basic] 
Option Strict
Option Explicit

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports Microsoft.VisualBasic

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))
            
            schema.Compile(AddressOf ShowCompileError)
            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 'Main
     
    
    Private Shared Sub ShowCompileError(sender As Object, e As ValidationEventArgs)
        Console.WriteLine("Validation Error: {0}", e.Message)
    End Sub 'ShowCompileError
End Class 'ValidXSD

[C#] 
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));

            schema.Compile(new ValidationEventHandler(ShowCompileError));
            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);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;

public __gc class ValidXSD {
public:
    static int main() {

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

            schema->Compile(new ValidationEventHandler(0, ShowCompileError));
            if (schema->IsCompiled) {
              // Schema is successfully compiled. 
              // Do something with it here.
            
            }
            return 0;
        } catch (XmlSchemaException* e) {
            Console::WriteLine(S"LineNumber = {0}", __box(e->LineNumber));
            Console::WriteLine(S"LinePosition = {0}", __box(e->LinePosition));
            Console::WriteLine(S"Message = {0}",e->Message);
            return -1;
        }

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

int main()
{
    ValidXSD::main();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Xml (in System.Xml.dll)

See Also

XmlSchemaException Members | System.Xml.Schema Namespace

Show: