1

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.

Kat Ze
  • 121
  • 1
  • 1
  • 5
  • Are you sure this line is correct? "result = new ValidationResult();" Do you have links to any sample code you are working from? – Justin C Aug 18 '15 at 13:31
  • ValidationResult implements IXPathNavigable sample code: http://stackoverflow.com/questions/24759417/validating-xml-with-schematron https://msdn.microsoft.com/en-us/library/aa468554.aspx – Kat Ze Aug 19 '15 at 12:21
  • where is your internal method validate being called from? – Justin C Aug 19 '15 at 17:43

1 Answers1

-1

I had this problem with xml, where were custom namespace, try to delete it from your xml

Risa
  • 147
  • 1
  • 2
  • 15