Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (46 sloc) 1.94 KB
using EdiFabric.Core.Model.Edi;
using EdiFabric.Examples.EDIFACT.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.EdifactD96A;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Xsl;
namespace EdiFabric.Examples.EDIFACT.MapEDI
{
class EDIToCustomObjectWithXslt
{
public static void Run()
{
Debug.WriteLine("******************************");
Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
Debug.WriteLine("******************************");
var ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\Edifact\PurchaseOrderCSV.txt");
List<IEdiItem> ediItems;
using (var ediReader = new EdifactReader(ediStream, "EdiFabric.Examples.EDIFACT.Templates.D96A.NoValidation"))
{
ediItems = ediReader.ReadToEnd().ToList();
}
var transactions = ediItems.OfType<TSORDERS>();
foreach (var transaction in transactions)
{
// Serialize each transaction
var xml = transaction.Serialize();
// Transform each XML
XDocument outputXml = new XDocument();
using (XmlWriter writer = outputXml.CreateWriter())
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\TemplateORDERSToPurchaseOrderMap.xslt")));
xslt.Transform(xml.CreateReader(), writer);
}
// Deserialize into the destination type
PurchaseOrder customTransaction = outputXml.Root.Deserialize<PurchaseOrder>();
}
}
}
}
You can’t perform that action at this time.