Click here to Skip to main content
12,951,619 members (64,255 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 7:28am
Updated 14-May-12 20:45pm
Nelek 14-Apr-12 13:42pm
added code tags

1 solution

Rate this: bad
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 15 May 2012
Copyright © CodeProject, 1999-2017
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