Exemplo n.º 1
0
        public static string XmlTransform(this ICakeContext context, string xsl, string xml, XmlTransformationSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(XmlTransformation.Transform(xsl, xml, settings));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs XML XSL transformation
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="xslPath">Path to xml style sheet.</param>
        /// <param name="xmlPath">Path xml data.</param>
        /// <param name="resultPath">Transformation result path.</param>
        /// <param name="settings">Settings for result file xml transformation.</param>
        public static void Transform(IFileSystem fileSystem, FilePath xslPath, FilePath xmlPath, FilePath resultPath, XmlTransformationSettings settings)
        {
            if (fileSystem == null)
            {
                throw new ArgumentNullException(nameof(fileSystem), "Null filesystem supplied.");
            }

            if (xslPath == null)
            {
                throw new ArgumentNullException(nameof(xslPath), "Null XML style sheet path supplied.");
            }

            if (xmlPath == null)
            {
                throw new ArgumentNullException(nameof(xmlPath), "Null XML data path supplied.");
            }

            if (resultPath == null)
            {
                throw new ArgumentNullException(nameof(resultPath), "Null result path supplied.");
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings), "Null settings supplied.");
            }

            IFile
                xslFile    = fileSystem.GetFile(xslPath),
                xmlFile    = fileSystem.GetFile(xmlPath),
                resultFile = fileSystem.GetFile(resultPath);

            if (!xslFile.Exists)
            {
                throw new FileNotFoundException("Xsl File not found.", xslFile.Path.FullPath);
            }

            if (!xmlFile.Exists)
            {
                throw new FileNotFoundException("XML File not found.", xmlFile.Path.FullPath);
            }

            if (!settings.Overwrite && resultFile.Exists)
            {
                throw new CakeException("Result file found and overwrite set to false.");
            }

            using (Stream
                   xslStream = xslFile.OpenRead(),
                   xmlStream = xmlFile.OpenRead(),
                   resultStream = resultFile.OpenWrite())
            {
                XmlReader
                    xslReader = XmlReader.Create(xslStream),
                    xmlReader = XmlReader.Create(xmlStream);

                var resultWriter = XmlWriter.Create(resultStream, settings.XmlWriterSettings);

                Transform(xslReader, xmlReader, resultWriter);
            }
        }
Exemplo n.º 3
0
        public static void XmlTransform(this ICakeContext context, FilePath xslPath, FilePath xmlPath, FilePath resultPath, XmlTransformationSettings settings)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            XmlTransformation.Transform(context.FileSystem, xslPath, xmlPath, resultPath, settings);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs XML XSL transformation
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="xslPath">Path to xml style sheet.</param>
        /// <param name="xmlPath">Path xml data.</param>
        /// <param name="resultPath">Transformation result path.</param>
        public static void Transform(IFileSystem fileSystem, FilePath xslPath, FilePath xmlPath, FilePath resultPath)
        {
            var settings = new XmlTransformationSettings();

            Transform(fileSystem, xslPath, xmlPath, resultPath, settings);
        }