validating xml file in .net2.0

C

cellardoor0716

I´m trying to validate a xml file against schema... I had to migrate
my code from .net 1.1(where I was using XMLValidatingReader and it was
working just fine...) to .net 2.0. The XMLValidatingReader became
obsolete, so I tried the XMLReader instead, but I always get only the
first error... Here is my sample code:

private void validate()
{
XmlSchemaSet xsc = new XmlSchemaSet();
xsc = this.getSchemaToValidate();

XmlReaderSettings xs = new XmlReaderSettings();
xs.ValidationType = ValidationType.Schema;
xs.ValidationFlags =
XmlSchemaValidationFlags.ReportValidationWarnings;
xs.ValidationEventHandler += new
ValidationEventHandler(ValidationCallback);
xs.Schemas.Add(xsc);
fs = new FileStream("XMLTest.xml", FileMode.Open, FileAccess.Read,
FileShare.Read);
XmlReader vr = XmlReader.Create(fs, xs);

while(vr.Read()) {}
}

private void ValidationCallback(object sender, ValidationEventArgs e)
{
tbErrorMessage += e.Message + Environment.NewLine;
this.numberOfValidationErrors++;
}

Can anyone help me with this?
 
M

Martin Honnen

xs.ValidationFlags =
XmlSchemaValidationFlags.ReportValidationWarnings;

This should usually be
xs.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;



If you still have problems then show us a minimal schema and minimal XML
you have problems with, the number and type of messages obviously
depends on the actual schema(s) and the XML.
 

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

Top