예제 #1
0
        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);
            }
        }
예제 #2
0
        private void Validate(string xmlDocumentPath, DocumentTypeConfig documentType)
        {
            Console.WriteLine("{0} Schematron validation started ", DateTime.Now);
            SchematronValidationConfig[] SchematronValidationConfig = documentType.SchematronValidationConfigs;
            XmlDocument document = new XmlDocument();

            Console.WriteLine("{0} Loading Xml Document '{1}'", DateTime.Now, xmlDocumentPath);
            document.Load(xmlDocumentPath);
            Console.WriteLine("{0} Instanciating the validator ", DateTime.Now);
            foreach (SchematronValidationConfig schematronValidationConfig in SchematronValidationConfig)
            {
                try
                {
                    SchematronValidator validator = new SchematronValidator(schematronValidationConfig);
                    Console.WriteLine("{0} Schematron validation", DateTime.Now);
                    validator.SchematronValidateXmlDocument(document);
                }
                catch (Exception ex)
                {
                    Debug.Fail("Something is wrong:" + ex.Message);
                    throw;
                }
            }

            Console.WriteLine("{0} Schematron validation completed", DateTime.Now);
        }