Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validating
Message
De
18/09/2003 04:28:32
 
 
À
17/09/2003 23:57:28
Information générale
Forum:
ASP.NET
Catégorie:
XML
Titre:
Divers
Thread ID:
00830186
Message ID:
00830202
Vues:
15
In one project I wrote procedure, which successfully validates XML against XSD. Because it have many differences with your code, I post it:
XmlTextReader xmltxtrdrImportXML = new XmlTextReader(opndlgImportXML.FileName);  //XML file was selected in open file dialog
xmlvldrdrImportXML = new XmlValidatingReader(xmltxtrdrImportXML);
XmlSchemaCollection xmlschcolImportXML = new XmlSchemaCollection();
//You miss namespace (it must be the same for schema and XML file) - you must specify it when adding schema to the collection
//ConfigurationSettings.AppSettings["XMLSchemaLocation"] holds physical path to the schema
xmlschcolImportXML.Add("http://tempuri.org/dstExchange.xsd", new XmlTextReader(ConfigurationSettings.AppSettings["XMLSchemaLocation"]));
xmlvldrdrImportXML.Schemas.Add(xmlschcolImportXML);
xmlvldrdrImportXML.ValidationType = ValidationType.Schema;
xmlvldrdrImportXML.ValidationEventHandler += new ValidationEventHandler(ValidationError); //ValidationError is handler for errors, which will be called when validation error was occured.
//Next code replaces your cycle for reader to read whole file
//It simply tries to load XML file into dataset, instanced from the same schema
dstExchange dstTestImport = new dstExchange();
dstTestImport.ReadXml(xmlvldrdrImportXML, XmlReadMode.IgnoreSchema);
In original procedure I was used flag to track whether validation errors was occured. If none, I was loaded XML file into second, real dataset (also instanciated from the same schema) without validating.

Plamen Ivanov
MCSD .NET Early Achiever and MCAD .NET Charter Member (VB .NET/SQL Server 2000)
MCSD (VB 6.0/SQL Server 2000)

VB (.NET) - what other language do you need in the whole Universe?...

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform