Returns detailed information about the schema exception.
Namespace:
System.Xml.Schema
Assembly:
System.Xml (in System.Xml.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
Public Class XmlSchemaException _
Inherits SystemException
Dim instance As XmlSchemaException
[SerializableAttribute]
public class XmlSchemaException : SystemException
[SerializableAttribute]
public ref class XmlSchemaException : public SystemException
public class XmlSchemaException extends SystemException
Security 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.
Option Strict On
Option Explicit On
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))
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 'Main
Private Shared Sub ShowCompileError(ByVal sender As Object, ByVal e As ValidationEventArgs)
Console.WriteLine("Validation Error: {0}", e.Message)
End Sub 'ShowCompileError
End Class 'ValidXSD
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);
}
}
#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;
};
System..::.Object
System..::.Exception
System..::.SystemException
System.Xml.Schema..::.XmlSchemaException
System.Xml.Schema..::.XmlSchemaInferenceException
System.Xml.Schema..::.XmlSchemaValidationException
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference