XmlValidatingReader 类已过时 [英] XmlValidatingReader class is obsolete
本文介绍了XmlValidatingReader 类已过时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 XmlValidatingReader 对象根据 xsd 架构验证我的对象,但此类在 .NEt 2.0 中已过时.有没有人有正确的代码来使用新的 Validation 类.
I am using XmlValidatingReader object to validat my object against a xsd schema but this class is obsolete in .NEt 2.0. Does any one have the right code to use the new Vaildation classes.
推荐答案
是:
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add ( .... );
settings.ValidationEventHandler += delegate( object sender, ValidationEventArgs e )
{
Console.WriteLine("invalid: " + e.Message);
};
XmlReader reader = XmlReader.Create (new XmlTextReader(file), settings);
这篇关于XmlValidatingReader 类已过时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文