XML and schema

  • Thread starter Thread starter Chris Wagner
  • Start date Start date
C

Chris Wagner

how do i validate a xml file with a schema using VB.net or C#? thanks
 
Hi Chris,

In my opinion is the most simple to open it in your VS.studio.net IDE

Cor
 
You can use XmlVaidatingReader for that purpose:


XmlTextReader xtr = new XmlTextReader("your xml file path");
XmlSchemaCollection schemColl = new XmlSchemaCollection();
schemColl.Add(null, "yourschemafile.xsd");
XmlValidatingReader valReader = new XmlValidatingReader(xtr);
valReader.ValidationType = ValidationType.Schema;
valReader.Schemas.Add(schemColl);
valReader.ValidationEventHandler += new ValidationEventHandler(valHandler);
// called if errors
while(valReader.Read())
{
// do nothing, just validate
}

Hope this helps.

Orlin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top