Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML validation
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.Schemas.Add("myNamespace", xsdUri);
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
Posted 14-Apr-12 8:28am
(unknown member)
Edited 14-May-12 21:45pm
v3
Comments
Nelek at 14-Apr-12 13:42pm
   
added code tags

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Afzaal Ahmad Zeeshan 82
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 15 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100