Exemplo n.º 1
0
        public static invoice MapToInvoice(string xml)
        {
            var    p            = new Saxon.Api.Processor();
            var    c            = p.NewXsltCompiler();
            string rootNodeName = XDocument.Load(xml).Root.Name.LocalName;

            Saxon.Api.XsltExecutable ex;
            if (rootNodeName == "Invoice")
            {
                ex = c.Compile(GenerateStreamFromString(Properties.Resources.ubl_invoice_xr));
            }
            else if (rootNodeName == "CrossIndustryInvoice")
            {
                ex = c.Compile(GenerateStreamFromString(Properties.Resources.cii_xr));
            }
            else
            {
                return(null);
            }
            var transformer = ex.Load();

            transformer.SetInputStream(File.OpenRead(xml), new Uri(@"C:\")); //TODO Temp URI
            var destination = new Saxon.Api.DomDestination();

            transformer.Run(destination);
            var ms = new MemoryStream();

            destination.XmlDocument.Save(ms);
            ms.Flush();
            ms.Position = 0;
            var s = new XmlSerializer(typeof(invoice));

            return((invoice)s.Deserialize(ms));
        }
Exemplo n.º 2
0
        public string Transform(Stream XMLStream, Stream xsltStream)
        {
            // Compile stylesheet

            var processor  = new Saxon.Api.Processor();
            var compiler   = processor.NewXsltCompiler();
            var executable = compiler.Compile(xsltStream);

            // Do transformation to a destination
            var destination = new Saxon.Api.DomDestination();

            // using (var inputStream = input.OpenRead())
            {
                var transformer = executable.Load();
                transformer.SetInputStream(XMLStream, new Uri("http://www.w3.org/"));
                transformer.Run(destination);
            }

            // Save result to a file (or whatever else you wanna do)
            // destination.XmlDocument.Save(output.FullName);
            return(destination.XmlDocument.OuterXml);
        }