本文整理匯總了C#中System.Xml.XmlValidatingReader.SchemaType屬性的典型用法代碼示例。如果您正苦於以下問題:C# XmlValidatingReader.SchemaType屬性的具體用法?C# XmlValidatingReader.SchemaType怎麽用?C# XmlValidatingReader.SchemaType使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。
在下文中一共展示了XmlValidatingReader.SchemaType屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
public class Sample{
public static void Main(){
XmlTextReader tr = new XmlTextReader("booksSchema.xml");
XmlValidatingReader vr = new XmlValidatingReader(tr);
vr.Schemas.Add(null, "books.xsd");
vr.ValidationType = ValidationType.Schema;
vr.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
while(vr.Read()){
if(vr.NodeType == XmlNodeType.Element){
if(vr.SchemaType is XmlSchemaComplexType){
XmlSchemaComplexType sct = (XmlSchemaComplexType)vr.SchemaType;
Console.WriteLine("{0}({1})", vr.Name, sct.Name);
}
else{
object value = vr.ReadTypedValue();
Console.WriteLine("{0}({1}):{2}", vr.Name, value.GetType().Name, value);
}
}
}
}
private static void ValidationCallBack (object sender, ValidationEventArgs args){
Console.WriteLine("***Validation error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
}
}