Hi All ,
I am validating XML files against an XML schema for which I read that the following code needs to be written (using XmlReaderSettings class)
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.Schemas = new System.Xml.Schema.XmlSchemaSet();
xmlSettings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(xmlUri, xmlSettings);
while (reader.Read()) ;
but what I don't understand is why should we validate xmls through the code ,when xmls can be validated in Visual studio by adding the XML schema namespace in the xml file we intend to validate ?
Thanks In Advance
Edited 14-May-12 20:45pm
Well,I seem to have found a satisfactory reason for why validation through code is done .
Its for the simple reason that ,In certain cases we dont want the users of our schema to simply ignore the errors thrown by the schema during static validation (i.e validation in Visual studio by specifying schema namespace in the xml file ;and no extra validation through code exists).We want the users to strictly adhere to the schema therefore we add extra validation through the code ,which throws an exception whenever there is an error in the xml.Untill the user corrects the xml,he cannot proceed.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)