本文整理匯總了C#中System.Xml.Schema.XmlSchemaException類的典型用法代碼示例。如果您正苦於以下問題:C# XmlSchemaException類的具體用法?C# XmlSchemaException怎麽用?C# XmlSchemaException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XmlSchemaException類屬於System.Xml.Schema命名空間,在下文中一共展示了XmlSchemaException類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
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);
}
}