private void InitializeService() { xslt = new CompiledXslt(AppDomain.CurrentDomain.BaseDirectory + xsltname); // serializer = new XmlSerializer(typeof(TimeSeriesResponseType)); serializer = new XmlSerializer(typeof(TimeSeriesResponseString)); }
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"); }
/// <summary> /// Method to transform any xmldocument with a given xslt /// </summary> /// <param name="xmlDoc">The xml document to transform</param> /// <param name="stylesheet">The xslt to transform xml document with</param> /// <returns>The transformed xml document</returns> public XmlDocument TransformXml(XmlDocument xmlDoc, CompiledXslt stylesheet) { XmlDocument xmlDocument = null; //XslCompiledTransform transform = PrecompiledStyleSheet(stylesheet); if (stylesheet != null && stylesheet.XslCompiledTransform != null) { xmlDocument = this.TransformXml(xmlDoc, stylesheet.XslCompiledTransform); } return(xmlDocument); }
/// <summary> /// Incepts the request and punes the input. /// </summary> /// <param name="message"></param> public override void InterceptRequest(InterceptorMessage message) { try { XmlDocument body = message.GetBody(); CompiledXslt styleSheet = LoadStyleSheet(body); XmlDocument transformedBody = _xsltUtility.TransformXml(body, styleSheet); message.SetBody(transformedBody); if (_configuration.PropagateOriginalMessage) { OriginalBody orgBody = new OriginalBody(body); message.AddProperty(ServerXsltTransformationBindingExtensionElement.ORIGINALBODYPROPERTYNAME, orgBody); } } catch (Exception ex) { throw new XsltTransformFailedException(ex); } }
private CompiledXslt LoadStyleSheet(XmlDocument body) { DocumentTypeConfig documentType = _searcher.FindUniqueDocumentType(body); //string path = documentType.XsltTransformStylesheetPath; string stylesheetPath; string basePath = ConfigurationManager.AppSettings["ResourceBasePath"]; if (string.IsNullOrEmpty(basePath)) { stylesheetPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, documentType.XsltTransformStylesheetPath); } else { stylesheetPath = Path.Combine(basePath, documentType.XsltTransformStylesheetPath); } CompiledXslt compiledXslt = new CompiledXslt(new FileInfo(stylesheetPath)); return(compiledXslt); }
private void InitializeService() { xslt = new CompiledXslt(AppDomain.CurrentDomain.BaseDirectory + Properties.Settings.Default.xsltV11toV10); // serializer = new XmlSerializer(typeof(TimeSeriesResponseType)); serializer = new XmlSerializer(typeof(TimeSeriesResponseString)); }