public SchematronValidator(IList <SchematronContext> contexts) { if (!contexts.IsEmpty()) { NMatrix.Schematron.Schema sch = new NMatrix.Schematron.Schema(); sch.Title = "CDA Validation Schema"; sch.NsManager = new XmlNamespaceManager(new XmlDocument().NameTable); sch.NsManager.AddNamespace("cda", "urn:hl7-org:v3"); sch.NsManager.AddNamespace("voc", "http://www.lantanagroup.com/voc"); Phase phase = sch.CreatePhase("CDAValidation"); sch.Phases.Add(phase); foreach (SchematronContext context in contexts) { Pattern pattern = phase.CreatePattern(context.Context); Rule rule = pattern.CreateRule(context.Context); rule.SetContext(sch.NsManager); foreach (SchematronRule schematronRule in context.Rules) { try { Assert assert = rule.CreateAssert(schematronRule.Test, schematronRule.Description); assert.SetContext(sch.NsManager); rule.Asserts.Add(assert); } catch (XPathException e) { LOG.Error("Failed to evaluate expression: " + schematronRule.Test); LOG.Error(e.Message); } catch (InvalidExpressionException e) { LOG.Error("Failed to evaluate expression: " + schematronRule.Test); LOG.Error(e.Message); } } pattern.Rules.Add(rule); sch.Patterns.Add(pattern); phase.Patterns.Add(pattern); } validator = new NMatrix.Schematron.Validator(); validator.AddSchema(sch); validator.Phase = phase.Id; initiated = true; } }