Project

Profile

Help

Support #5152 » Program.cs

The code snippet for the validation - Orlando Ribeiro, 2021-11-03 12:34

 
using System;
using System.Diagnostics;
using System.IO;

using Saxon.Api;
using Saxon.Eej.config;

namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
var xmlData = File.ReadAllText(@"c:\temp\CIUS\DocExemplo.xml");
var xslData = File.ReadAllText(@"c:\temp\CIUS\urn_feap.gov.pt_CIUS-PT_2.1.1_Full-compiled.xsl");

var data = TransformXml(xmlData, xslData);
}


public static string TransformXml(string xmlData, string xslData)
{
EnterpriseConfiguration conf = new EnterpriseConfiguration();
conf.setConfigurationProperty(FeatureKeys.LICENSE_FILE_LOCATION, @"c:\temp\CIUS\saxon-license.lic");

var xsltProcessor = new Processor(conf);
var documentBuilder = xsltProcessor.NewDocumentBuilder();
documentBuilder.BaseUri = new Uri("file://");
var xdmNode = documentBuilder.Build(new StringReader(xmlData));

var xsltCompiler = xsltProcessor.NewXsltCompiler();
var xsltExecutable = xsltCompiler.Compile(new StringReader(xslData));
var xsltTransformer = xsltExecutable.Load();
xsltTransformer.InitialContextNode = xdmNode;
xsltTransformer.MessageListener = new Action<Saxon.Api.Message>((a) =>
{
Debug.Print(a.Content.ToString());
});

var results = new XdmDestination();

xsltTransformer.Run(results);
return results.XdmNode.OuterXml;
}

}
}
(3-3/3)