I am trying to validate CDA (xml) documents by using schematron. I already have all schematron files I need (they have extension .sch). For validating i use NMatrix.Schematron.Validator class from schematron.net
http://sourceforge.net/projects/dotnetopensrc/
This is my code:
class CDALetterValidator
{
private CDALetter cdaLetter;
private Validator validator;
private String file { get; set; }
IXPathNavigable result;
public CDALetterValidator(String fileName)
{
validator = new Validator();
validator.AddSchema(new XmlTextReader("C:/pathToSchFile"));
file = fileName;
result = new ValidationResult();
}
internal void validate()
{
while (!System.IO.File.Exists(file))
{
System.Threading.Thread.Sleep(300);
}
try
{
result = validator.Validate(new XmlTextReader(file));
}
catch (ValidationException ex)
{
Console.WriteLine(ex.Message);
}
}
}
As i could see while debugging my schematron file is recognized by the validator class but it does not validate correct because I tried it with xml Files, which are of course not valid and in such a case there is an exception expected to be thrown but it isnt.
Does anyone has experiences with schematron.net? Or even an idea what is going wrong? By the way: The .sch File is definitly correct, so the mistake is either in my implementation or in schematron.net library.