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?
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?