how to use my own EDI template class for conversion from EDI to XML using EDIfabric?

193 Views Asked by At

EDIfarbic uses its own POCO class for reading and converting EDI file to intermediate data, I want my own POCO class to replace theirs, for example, they are using TS850 class for converting x12 850 EDI file to XML,but i want to use my own class format X12_00401_850. here is the code that is using TS850 class for conversion:

using (var stream = new FileStream("C:\\Users\\custom-schema.xsd", FileMode.Open))
        {
            var serializer = new XmlSerializer(typeof(TS850), "http://schemas.microsoft.com/BizTalk/EDI/X12/2006");
            var xmlDataWriterSettings = new XmlWriterSettings { Indent = true };
            using (var ediReader = new X12Reader(File.OpenRead("C:\\Users\\850.edi"), "EdiFabric.Templates.X12"))
            {
                var ediItems = ediReader.ReadToEnd().ToList();
                var transactions = ediItems.OfType<TS850>();
                foreach (var transaction in transactions)
                {
                   
                    serializer.Serialize(XmlWriter.Create(File.Create("C:\\Users\\output.xml"), xmlDataWriterSettings), transaction);
                }
                Console.WriteLine("file is made");
            }
        }

    }

I tried to change the type from TS850 to my class, but it didn't work. The only option I have is to map the TS850 class to my class, but is there any other way where it could directly be converted?

0

There are 0 best solutions below