使用 C# 解析 EDI 平面文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2046553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:59:32  来源:igfitidea点击:

EDI Flat File parsing with C#?

c#parsingflat-fileedix12

提问by ElHaix

Initially I was thinking to use SSIS to parse an EDI file, however I've seen a few manual EDI parsers (field mapping), and would like to use automate this functionality in C#.

最初我想使用 SSIS 来解析 EDI 文件,但是我已经看到了一些手动 EDI 解析器(字段映射),并且想在 C# 中使用自动化这个功能。

Example EDI File:

EDI 文件示例:

Example EDI File

EDI 文件示例

回答by cfbarbero

I'm not familiar with the EDI file format, but would either of these help:

我不熟悉 EDI 文件格式,但以下任一方法都有帮助:

回答by MarlonRibunal

I am not sure if you are open to commercial tools, but I am throwing this link out here just in case. It might help somebody. Disclaimer: I am not connected in any way to this provider.

我不确定您是否对商业工具持开放态度,但我将这个链接放在这里以防万一。它可能会帮助某人。免责声明:我与此提供商没有任何联系。

FRAMEWORK EDI - EDI Tools for Programmer (Commercial Framework) - Find it here: http://www.edidev.com/

FRAMEWORK EDI - 程序员的 EDI 工具(商业框架) - 在这里找到:http: //www.edidev.com/

回答by Paul Tyng

This is for X12 and worked pretty well for my uses:

这是针对 X12 的,非常适合我的用途:

http://x12parser.codeplex.com/

http://x12parser.codeplex.com/

It's command line, and just outputs an XML file for your EDI file.

它是命令行,只是为您的 EDI 文件输出一个 XML 文件。

You could possibly adapt it for your purposes.

您可以根据自己的目的调整它。

回答by cleftheris

There is EDI.Netlibrary which is opensource and supports all three known EDI formats (X12, EDIFact, Tradacoms). In your case for X12 you need to provide a custom implementation of the IEdiGrammarwith the following presets.

EDI.Net库,它是开源的,并支持所有三种已知EDI格式(X12,EDIFACT,TRADACOMS)。对于 X12,您需要提供IEdiGrammar具有以下预设的自定义实现。

public class EDI_X12Grammar : IEdiGrammar
{
...
}

var grammar = new EDI_X12Grammar() 
       {
            ComponentDataElementSeparator = new[] { '>' },
            DataElementSeparator = new[] { '*' },
            DecimalMark = null,
            ReleaseCharacter = null,
            Reserved = new char[0],
            SegmentTerminator = '~',
            ServiceStringAdviceTag = null,
            InterchangeHeaderTag = "ISA",
            FunctionalGroupHeaderTag = "GS",
            MessageHeaderTag = "ST",
            MessageTrailerTag = "SE",
            FunctionalGroupTrailerTag = "GE",
            InterchangeTrailerTag = "IEA",
        };

Disclaimer I wrote the library.

免责声明我写了图书馆。