English 中文(简体)
How do I parse EDIFACT in Java? [closed]
原标题:

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Parsing EDIFACT can be a daunting undertaking. How can I correctly create the syntactically and semantically correct tree from an EDIFACT file?

最佳回答

www.smooks.org - A template-based text parser. They have suitable EDI examples that I was looking to use to implement for Walmart 810s before they dumped my products.

问题回答

try: http://bots.sourceforge.net not so much a library, but translates edifact to the format you prefer....xml....csv....etc

Parsing EDIFACT is easy. You can find many libraries to do it. For example,

http://code.google.com/p/edicoder/

All these libraries simply break up the messages into segments.

The hard part with EDIFACT is to transform the message into some meaningful objects. This is very application specific and I doubt you will find any libraries. Even if you find one, it will be specific to a narrow field, like hotel reservation.

We have implemented 834 EDI to XML using Java + Smooks 1.6. It s awesome!

<?xml version="1.0" encoding="UTF-8"?>

<medi:description name="834 EDI TO XML" version="1.0" />

<medi:delimiters segment="&#10;" 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>

There is a good one at http://x12parser.codeplex.com. It will output any 810 as xml, html or back to text with whitespace for easier inspection. The unit tests includes a sample of the Walmart 810 from the site: http://www.jobisez.com/edi/tp/guide.aspx?doc=/edi-igs/Walmart/810Invoice5010.pdf.

The formatted text would look like this:

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




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签