如何在 Java 中解析 EDIFACT? [关闭]
Posted
技术标签:
【中文标题】如何在 Java 中解析 EDIFACT? [关闭]【英文标题】:How do I parse EDIFACT in Java? [closed] 【发布时间】:2011-02-17 03:59:04 【问题描述】:解析 EDIFACT 可能是一项艰巨的任务。如何从 EDIFACT 文件正确创建语法和语义正确的树?
【问题讨论】:
【参考方案1】:www.smooks.org - 基于模板的文本解析器。他们有合适的 EDI 示例,我希望在他们倾销我的产品之前将其用于沃尔玛 810s。
【讨论】:
Smooks 似乎非常依赖 XML,但其他方面看起来成熟且不错。 是的。老实说,我希望看到类似 EDIFACT 的 commons-digester 之类的东西。在我完全停止做 EDI 之前,我正在考虑使用 Smooks 做一些类似的、直接的 EDI 文本到 POJO。【参考方案2】:试试:http://bots.sourceforge.net 与其说是一个库,不如说是把 edifact 翻译成你喜欢的格式....xml..csv....等
【讨论】:
【参考方案3】:解析 EDIFACT 很容易。你可以找到很多图书馆来做到这一点。例如,
http://code.google.com/p/edicoder/
所有这些库都只是将消息分解成段。
EDIFACT 的难点在于将消息转换为一些有意义的对象。这是非常特定于应用程序的,我怀疑您会找到任何库。即使你找到了,它也只是一个狭窄的领域,比如酒店预订。
【讨论】:
Edicoder 看起来还没有真正实现任何解析代码。我同意 EDIFACT 转换。【参考方案4】:我们已经使用 Java + Smooks 1.6 实现了 834 EDI 到 XML。太棒了!
<?xml version="1.0" encoding="UTF-8"?>
<medi:description name="834 EDI TO XML" version="1.0" />
<medi:delimiters segment=" " field="*" component="^"
sub-component="#" escape="~"/>
<medi:segments xmltag="FILE">
<medi:segment segcode="ISA" xmltag="ISAHeader">
<medi:field xmltag="AuthorziationInformationQualifier" />
<medi:field xmltag="AuthorziationInformation" />
<medi:field xmltag="SecurityInformationQualifier" />
<medi:field xmltag="InterchangeIDQualifier" />
<medi:field xmltag="InterchangeSenderID" />
<medi:field xmltag="InterchangeIDQualifier" />
<medi:field xmltag="InterchangeReceiverID" />
<medi:field xmltag="InterchangeDate" />
<medi:field xmltag="InterchangeTime" />
<medi:field xmltag="RepetitionSeparator" />
<medi:field xmltag="InterchangeControlVersionNumber" />
<medi:field xmltag="InterchangeControlNumber" />
<medi:field xmltag="AcknowledgmentRequested" />
<medi:field xmltag="InterchangeUsageIndicator" />
<medi:field xmltag="ComponentElementSeparator" />
</medi:segment>
<medi:segmentGroup xmltag="BenefitEnrollmentRequest" maxOccurs="-1">
<medi:segment minOccurs="0" maxOccurs="-1" segcode="GS" xmltag="BenefitEnrollmentRequestHeader">
<medi:field xmltag="FunctionalIDCode" />
<medi:field xmltag="ApplicationSendsCode" />
<medi:field xmltag="ApplicationRecsCode" />
<medi:field xmltag="Date" />
<medi:field xmltag="Time" />
<medi:field xmltag="GroupCtrlNumber" />
<medi:field xmltag="ResponsibleAgencyCode" />
<medi:field xmltag="ReleaseIDCode" />
</medi:segment>
<medi:segmentGroup xmltag="BenefitEnrollmentMaintenance" maxOccurs="-1">
<medi:segment minOccurs="0" maxOccurs="-1" segcode="ST" xmltag="BenefitEnrollmentMaintenanceHeader">
<medi:field xmltag="TransactionSetIdentifierCode" />
<medi:field xmltag="TransactionSetControlNumber" />
<medi:field xmltag="ImplementationConventionReference" />
</medi:segment>
<medi:segment minOccurs="0" segcode="BGN" xmltag="Begin" ignoreUnmappedFields="true">
<medi:field xmltag="TSPurposeCode" />
<medi:field xmltag="ReferenceIdent" />
<medi:field xmltag="Date" />
<medi:field xmltag="Time" />
<medi:field xmltag="TimeCode" />
<medi:field xmltag="ReferenceIdent" />
<medi:field xmltag="TransactionTypeCode" />
<medi:field xmltag="ActionCode" />
</medi:segment>
<medi:segment minOccurs="0" segcode="REF" xmltag="Ref_38" ignoreUnmappedFields="true">
<medi:field xmltag="ReferenceIdentQual" />
<medi:field xmltag="ReferenceIdent" />
</medi:segment>
<medi:segment minOccurs="0" segcode="DTP" xmltag="Dtp_007" ignoreUnmappedFields="true">
<medi:field xmltag="DateTimeQualifier" />
<medi:field xmltag="DateTimePeriodFormatQualifier" />
<medi:field xmltag="DateTimePeriod" />
</medi:segment>
<medi:segment minOccurs="0" segcode="QTY" xmltag="To" ignoreUnmappedFields="true">
<medi:field xmltag="QuantityQualifier" />
<medi:field xmltag="Quantity" />
</medi:segment>
<medi:segment minOccurs="0" segcode="N1" xmltag="Sponsor" ignoreUnmappedFields="true">
<medi:field xmltag="EntityIDCode" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
</medi:segment>
<medi:segment minOccurs="0" segcode="N1" xmltag="Issuer" ignoreUnmappedFields="true">
<medi:field xmltag="EntityIDCode" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
</medi:segment>
<medi:segment minOccurs="0" segcode="N1" xmltag="Agent" ignoreUnmappedFields="true">
<medi:field xmltag="EntityIDCode" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
<medi:segment minOccurs="0" segcode="ACT" xmltag="Act" ignoreUnmappedFields="true">
<medi:field xmltag="AccountNumber" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
<medi:field xmltag="AcctNumberQualifier" />
<medi:field xmltag="AccountNumber" />
</medi:segment>
</medi:segment>
<medi:segment minOccurs="0" segcode="N1" xmltag="Broker" ignoreUnmappedFields="true">
<medi:field xmltag="EntityIDCode" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
<medi:segment minOccurs="0" segcode="ACT" xmltag="Act" ignoreUnmappedFields="true">
<medi:field xmltag="AccountNumber" />
<medi:field xmltag="Name" />
<medi:field xmltag="IDCodeQualifier" />
<medi:field xmltag="IDCode" />
<medi:field xmltag="AcctNumberQualifier" />
<medi:field xmltag="AccountNumber" />
</medi:segment>
</medi:segment>
<!--
<medi:segment minOccurs="0" segcode="N1" xmltag="Sponsor">
<medi:field xmltag="Name" />
</medi:segment>
<medi:segmentGroup xmltag="Member" maxOccurs="-1">
<medi:segment minOccurs="0" maxOccurs="-1" segcode="INS" xmltag="MemberHeader">
<medi:field xmltag="HeaderName" />
</medi:segment>
<medi:segment minOccurs="0" segcode="DTP" xmltag="DOB">
<medi:field xmltag="Month" />
</medi:segment>
<medi:segment minOccurs="0" maxOccurs="-1" segcode="LE" xmltag="MemberFooter" ignoreUnmappedFields="true">
<medi:field xmltag="FooterName"/>
</medi:segment>
</medi:segmentGroup>-->
<medi:segment minOccurs="0" segcode="SE" xmltag="BenefitEnrollmentMaintenanceFooter">
<medi:field xmltag="TransactionSetIdentifierCode" />
<medi:field xmltag="TransactionSetControlNumber" />
</medi:segment>
</medi:segmentGroup>
<medi:segment minOccurs="0" segcode="GE" xmltag="BenefitEnrollmentRequestFooter">
<medi:field xmltag="ZFA" />
</medi:segment>
</medi:segmentGroup>
<medi:segment segcode="IEA" xmltag="ISAFooter">
<medi:field xmltag="CCC" />
</medi:segment>
</medi:segments>
【讨论】:
【参考方案5】:http://x12parser.codeplex.com 有一个很好的。 它将任何 810 输出为 xml、html 或带空格的文本,以便于检查。单元测试包括来自网站的 Walmart 810 样本:http://www.jobisez.com/edi/tp/guide.aspx?doc=/edi-igs/Walmart/810Invoice5010.pdf。
格式化的文本如下所示:
ISA*00* *00* *16*102096559TEST *14*PARTNERTEST *071214*1406*U*00040*810000263*1*T*>
GS*IN*102096559TEST*PARTNER*20071214*1406*810000263*X*004010
ST*810*0001
BIG*20050205*6463367*20050202*3376103367
REF*IA*123456170
REF*DP*00017
REF*MR*0020
N1*SU*SUPPLIER NAME
N1*ST*WAL-MART 100*UL*0078742000992
N3*406 SOUTH WALTON BLVD
N4*BENTONVILLE*AR*72712
ITD*05*15*****45
DTM*011*20050205
FOB*CC
IT1**1080*EA*3.61**IN*001719653*UP*022108955228*UK*00221089552284
PID*F****ITEM DESCRIPTION
SAC*A*I410***2350*******02
TDS*387530
CAD*T***RDWT*ROADWAY**BM*123456789
ISS*1080*EA*100*LB
CTT*1
SE*19*0001
GE*1*810000263
IEA*1*810000263
【讨论】:
x12parser 是在 .NET 中实现的,而不是 Java... :-)以上是关于如何在 Java 中解析 EDIFACT? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
dotNet 中的开源 EDIFACT baplie 解析器?
是否有人在 X12 或 EDIFACT 中有包含二进制数据的示例文件?
SFTP 连接器和 EDIFACT 连接器可以在 Mule 社区版中实现吗?