Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlSchemaException Class

Returns detailed information about the schema exception.

Namespace: System.Xml.Schema
Assembly: System.Xml (in system.xml.dll)

[SerializableAttribute] 
public ref class XmlSchemaException : public SystemException
/** @attribute SerializableAttribute() */ 
public class XmlSchemaException extends SystemException
SerializableAttribute 
public class XmlSchemaException extends SystemException
Not applicable.
Security noteSecurity Note:

The XmlSchemaException class may contain sensitive information that should not be exposed in untrusted scenarios. For example, the SourceUri property returns the URI path to the schema file that caused the exception. 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.

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;
};

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.