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.
Asked
Active
Viewed 8,772 times
2 Answers
18
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);

Frederik Gheysels
- 56,135
- 11
- 101
- 154
-3
Check the MSDN documentation for XmlValidatingReader and you'll see in the [ObsoleteAttribute] attribute this:
"Use XmlReader created by XmlReader.Create() method using appropriate XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202"

Jay Riggs
- 53,046
- 9
- 139
- 151
-
2How could this be an answer? It's exactly the message you already got from Visual Studio! – edc65 Nov 03 '15 at 15:32
-
I agree with @edc65 – Janatbek Orozaly Jul 22 '21 at 19:03