/** * */ public void TranslateInputDocument() { if (_content != null && IsParsible()) { try { //---------------------------------// //--- Setup XML reader settings ---// //---------------------------------// ValidationEventHandler validationHandler = (s, ee) => LogManager.SourceError(SOURCE, ee.Exception); var settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.None; settings.ValidationFlags = XmlSchemaValidationFlags.None; settings.ValidationEventHandler += validationHandler; string content = Encoding.UTF8.GetString(_content); if (string.IsNullOrWhiteSpace(content)) return; using (var sr = new StringReader(content)) { using (XmlReader xrXml = new XmlTextReader(sr)) { var doc = new XPathDocument(xrXml); string xsdName = SchemaManager.GetSchemaName(Encoding.UTF8.GetString(_content)); string xslName = xsdName.Replace(".xsd", ".xsl"); StringReader xslReader = GetXSLReader(xslName); var xr = new XmlTextReader(xslReader); var xslt = new XslCompiledTransform(); xslt.Load(xr); //--------------------------------------------------------------------------// //--- Create an XsltArgumentList for custom transformation functionality ---// //--------------------------------------------------------------------------// var xslArg = new XsltArgumentList(); var fileName = ProjectManager.ProjectName + ATMLContext.ATML_CONFIG_FILENAME_SUFFIX; xslArg.AddParam("documentName", "", fileName ); // Add an object to calculate the new book price. var obj = new ReaderTools(); //TODO: Figure out all the functionality required for translation xslArg.AddExtensionObject("urn:utrs.atml-reader-tools", obj); //---------------------------// //--- Transform the file. ---// //---------------------------// using (var w = new StringWriter()) { var stringBuilder = new StringBuilder(); var xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; xws.NewLineOnAttributes = false; xws.NamespaceHandling = NamespaceHandling.OmitDuplicates; using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xws)) { xslt.Transform(doc, xslArg, xmlWriter); LogManager.SourceTrace(SOURCE, "ATML translation Completed"); try { Console.Write(stringBuilder.ToString()); _testConfiguration = TestConfiguration15.Deserialize(stringBuilder.ToString()); } catch (Exception e) { LogManager.SourceError(SOURCE, "An error has occurred attempting to marshall the translated document into an ATML Test Configuration object.", e); } OnTranslatedInputDocument(_testConfiguration); } } } } } catch (Exception ee) { LogManager.SourceError(SOURCE, ee, "An error has occurred attempting to process the input document."); } } }
/** * */ public void TranslateInputDocument() { if (_content != null && IsParsible()) { try { //---------------------------------// //--- Setup XML reader settings ---// //---------------------------------// ValidationEventHandler validationHandler = (s, ee) => LogManager.SourceError(SOURCE, ee.Exception); var settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.None; settings.ValidationFlags = XmlSchemaValidationFlags.None; settings.ValidationEventHandler += validationHandler; string content = Encoding.UTF8.GetString(_content); if (string.IsNullOrWhiteSpace(content)) { return; } using (var sr = new StringReader(content)) { using (XmlReader xrXml = new XmlTextReader(sr)) { var doc = new XPathDocument(xrXml); string xsdName = SchemaManager.GetSchemaName(Encoding.UTF8.GetString(_content)); string xslName = xsdName.Replace(".xsd", ".xsl"); StringReader xslReader = GetXSLReader(xslName); var xr = new XmlTextReader(xslReader); var xslt = new XslCompiledTransform(); xslt.Load(xr); //--------------------------------------------------------------------------// //--- Create an XsltArgumentList for custom transformation functionality ---// //--------------------------------------------------------------------------// var xslArg = new XsltArgumentList(); var fileName = ProjectManager.ProjectName + ATMLContext.ATML_CONFIG_FILENAME_SUFFIX; xslArg.AddParam("documentName", "", fileName); // Add an object to calculate the new book price. var obj = new ReaderTools(); //TODO: Figure out all the functionality required for translation xslArg.AddExtensionObject("urn:utrs.atml-reader-tools", obj); //---------------------------// //--- Transform the file. ---// //---------------------------// using (var w = new StringWriter()) { var stringBuilder = new StringBuilder(); var xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Indent = true; xws.NewLineOnAttributes = false; xws.NamespaceHandling = NamespaceHandling.OmitDuplicates; using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xws)) { xslt.Transform(doc, xslArg, xmlWriter); LogManager.SourceTrace(SOURCE, "ATML translation Completed"); try { Console.Write(stringBuilder.ToString()); _testConfiguration = TestConfiguration15.Deserialize(stringBuilder.ToString()); } catch (Exception e) { LogManager.SourceError(SOURCE, "An error has occurred attempting to marshall the translated document into an ATML Test Configuration object.", e); } OnTranslatedInputDocument(_testConfiguration); } } } } } catch (Exception ee) { LogManager.SourceError(SOURCE, ee, "An error has occurred attempting to process the input document."); } } }