Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlValidatingReader class is obsolete

Tags:

xml

xsd

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.

like image 501
chugh97 Avatar asked Mar 10 '09 14:03

chugh97


1 Answers

Yes:

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);
like image 155
Frederik Gheysels Avatar answered Nov 14 '22 03:11

Frederik Gheysels