public void Validate(XmlDocument document) { try { this.logger.Trace("SchematronValidation"); if (document == null) { throw new SchematronValidationInterceptionEmptyBodyException(); } DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(document); SchematronStore store = new SchematronStore(); SchematronValidationConfig[] schematronValidationConfigCollection = documentType.SchematronValidationConfigs; foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection) { CompiledXslt compiledXsltEntry = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath); SchematronValidator validator = new SchematronValidator(schematronValidationConfig.ErrorXPath, schematronValidationConfig.ErrorMessageXPath); validator.SchematronValidateXmlDocument(document, compiledXsltEntry); } } catch (SchematronErrorException ex) { this.logger.Info("XmlDocument rejected, as it contant at least one schematron error."); throw new SchematronValidateDocumentFailedException(ex); } catch (Exception ex) { this.logger.Error("Schematron validation failed", ex); throw new SchematronValidateDocumentFailedException(ex); } }
public void _02_GetTwiceTest() { Console.WriteLine(DateTime.Now + " GetTwiceTest start"); XmlDocument document = new XmlDocument(); document.Load(TestConstants.PATH_INVOICE_XML); DocumentTypeConfigSearcher searcher = new DocumentTypeConfigSearcher(); DocumentTypeConfig documentTypeConfig = searcher.FindUniqueDocumentType(document); SchematronStore store = new SchematronStore(); SchematronValidationConfig[] schematronValidationConfigCollection = documentTypeConfig.SchematronValidationConfigs; foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection) { CompiledXslt transform = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath); Assert.IsNotNull(transform); Assert.IsNotNull(transform.XslCompiledTransform); } schematronValidationConfigCollection = documentTypeConfig.SchematronValidationConfigs; foreach (SchematronValidationConfig schematronValidationConfig in schematronValidationConfigCollection) { CompiledXslt transform = store.GetCompiledSchematron(schematronValidationConfig.SchematronDocumentPath); Assert.IsNotNull(transform); Assert.IsNotNull(transform.XslCompiledTransform); } Console.WriteLine(DateTime.Now + " GetTwiceTest stop"); }