Giter VIP home page Giter VIP logo

edifactconverter's Introduction

-edifactconverter-

First Steps

you need maven, ant and jdk 1.8 installed on your computer.

Open a command line shell in a local directory.

Clone the repository into that directory. (Have a look at the git documentation on how to do that) You the get a lot of sub directories which hold many maven sub projects.

openedifact-converter => Holds the converter jar after the build. openedifact-sample-01 => Not used so far. openedifact-un2xsd => Holds the xsd generator jar after build (if you want to generate xsd files yourself). openedifact-xsd-libs- => Holds the jar files containing the Edifact xsd files for that Edifact release. Issue a "mvn clean install" on the command line. It should then start the build which takes some time. As a result, you find the resulting jar files under the respective "target" sub directory.

The Parser:

The parser works in such a way that it uses the appropriate xsd file to analyse the data to be processed. The xsd schema files must be present on the classpath in order to work, otherwise you will get an exception. For each message type to be processed there must be an appropriate xsd schema file.

E.g. if you want to parse 07a INVOIC, then you need an EDIFACTINTERCHANGE_INVOIC_07A.xsd on the classpath. The filename is important here, it must always look like this: EDIFACTINTERCHANGE_[Messagetype]_[Version].xsd

How to use the converter

Put the openedifact-converter-2.2-SNAPSHOT.jar (the version might change) file on the classpath

Put the sxd schema files you need on the classpath

To convert from flat UN/EDIFACT to XML you proceed like this:

com.openedi.sax.EdifactSaxParserToXML theXmlParser = EdifactSaxParserToXML .factory("UTF-8"); "<Encoding e.g. UTF-8" );

String edifactXml = xmlParser.parseEdifact(in); "InputSource an Edifact flat file instance as InputSource or String

To convert from flat from XML to UN/EDIFACT you proceed like this: com.openedi.sax.EdifactSaxParserToFlat theFlatParser = EdifactSaxParserToFlat.factory( false ); "false means non validating

String flatEdifact = flatParser.parse( "" );

2018.04.30: There is a new method which can be used for parsing, if and only if the EDIFACT-XML carries a namespaceprefix for each XML tag:

String parse(String inputXML, String nameSpacePrefix) throws Exception;

This might be necessary, as the determination of the message version and therewith the XSD which has to be used for parsing is been done with simple String methods. And here in order to get the offsets correct, we might need the namespace prefix.

There is a conveniance class to run the converter directly from the command line.

After having build the project (see above), you can call the conveter like this:

Create a testing directoy

Copy openedifact-converter-2.2-SNAPSHOT.jar as well as the xsd jars for the version you like to use (e.g. openedifact-xsd-libs-07A-1.1-SNAPSHOT.jar) in your testing directory

Issue java -cp openedifact-converter-2.2-SNAPSHOT.jar:openedifact-xsd-libs--1.1-SNAPSHOT.jar com.sapstern.openedifact.run.ConverterRunner -process flat/xml -fileIn your xml/edi file -ns you can put your xml namespace here only if converting to flat

edifactconverter's People

Contributors

dependabot[bot] avatar sapstern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

edifactconverter's Issues

Mojibake issue of EdifactSaxParserToXMLIF#parseEdifact(java.lang.String) with UTF-8 input string

Please help to check the mojibake issue with the function EdifactSaxParserToXMLIF#parseEdifact(java.lang.String).

version=2.2-SNAPSHOT
groupId=com.sapstern.openedifact
artifactId=openedifact-converter

The code is simple like below:

EdifactSaxParserToXMLIF xmlParser =  EdifactSaxParserToXML.factory("UTF-8",false);
String xml = xmlParser.parseEdifact(edifact);

input string is:

UNA:+.? '
UNB+UNOX:3+SABICSAP:14+3PL_APAC:14+210609:0555+00000186242603'
UNH+0010119646+PARTIN:D:01B:UN'
BGM+10+0000000186242603+5'
DTM+137:20210609:204'
UNS+D'
NAD+OY+0010119646++Geosyn Thetics Technologies+广州保税区东涌路8号A216室+广州+190+510000+CN'
FTX+WHI++MAXPARTIALS+9'
FTX+WHI++PARTIALITEM+C'
FTX+WHI++TOLOVER+10.0'
FTX+WHI++TOLUNDER+10.0'
CTA+CN+:Geosyn Thetics Technologies'
COM+020-38139353:TE'
COM+NA:EM'
TOD+6++:::DDP'
LOC+1+:::GUANGDONG'
UNT+15+0010119646'
UNZ+1+00000186242603'

output is:

<?xml version="1.0" encoding="UTF-8"?>
<EDIFACTINTERCHANGE>
    <S_UNA>
        <D_UNA1>:</D_UNA1>
        <D_UNA2>+</D_UNA2>
        <D_UNA3>.</D_UNA3>
        <D_UNA4>?</D_UNA4>
        <D_UNA5>*</D_UNA5>
        <D_UNA6>'</D_UNA6>
    </S_UNA>
    <S_UNB>
        <C_S001>
            <D_0001>UNOX</D_0001>
            <D_0002>3</D_0002>
        </C_S001>
        <C_S002>
            <D_0004>SABICSAP</D_0004>
            <D_0007>14</D_0007>
        </C_S002>
        <C_S003>
            <D_0010>3PL_APAC</D_0010>
            <D_0007>14</D_0007>
        </C_S003>
        <C_S004>
            <D_0017>210609</D_0017>
            <D_0019>0555</D_0019>
        </C_S004>
        <D_0020>00000186242603</D_0020>
    </S_UNB>
    <M_PARTIN_01B>
        <S_UNH>
            <D_0062>0010119646</D_0062>
            <C_S009>
                <D_0065>PARTIN</D_0065>
                <D_0052>D</D_0052>
                <D_0054>01B</D_0054>
                <D_0051>UN</D_0051>
            </C_S009>
        </S_UNH>
        <S_BGM>
            <C_C002>
                <D_1001>10</D_1001>
            </C_C002>
            <C_C106>
                <D_1004>0000000186242603</D_1004>
            </C_C106>
            <D_1225>5</D_1225>
        </S_BGM>
        <S_DTM>
            <C_C507>
                <D_2005>137</D_2005>
                <D_2380>20210609</D_2380>
                <D_2379>204</D_2379>
            </C_C507>
        </S_DTM>
        <S_UNS>
            <D_0081>D</D_0081>
        </S_UNS>
        <G_PARTIN_01B_SG4>
            <S_NAD>
                <D_3035>OY</D_3035>
                <C_C082>
                    <D_3039>0010119646</D_3039>
                </C_C082>
                <C_C080>
                    <D_3036>Geosyn Thetics Technologies</D_3036>
                </C_C080>
                <C_C059>
                    <D_3042>������������������������8���A216���</D_3042>
                </C_C059>
                <D_3164>������</D_3164>
                <C_C819>
                    <D_3229>190</D_3229>
                </C_C819>
                <D_3251>510000</D_3251>
                <D_3207>CN</D_3207>
            </S_NAD>
            <S_FTX>
                <D_4451>WHI</D_4451>
                <C_C107>
                    <D_4441>MAXPARTIALS</D_4441>
                </C_C107>
                <C_C108>
                    <D_4440>9</D_4440>
                </C_C108>
            </S_FTX>
            <S_FTX>
                <D_4451>WHI</D_4451>
                <C_C107>
                    <D_4441>PARTIALITEM</D_4441>
                </C_C107>
                <C_C108>
                    <D_4440>C</D_4440>
                </C_C108>
            </S_FTX>
            <S_FTX>
                <D_4451>WHI</D_4451>
                <C_C107>
                    <D_4441>TOLOVER</D_4441>
                </C_C107>
                <C_C108>
                    <D_4440>10.0</D_4440>
                </C_C108>
            </S_FTX>
            <S_FTX>
                <D_4451>WHI</D_4451>
                <C_C107>
                    <D_4441>TOLUNDER</D_4441>
                </C_C107>
                <C_C108>
                    <D_4440>10.0</D_4440>
                </C_C108>
            </S_FTX>
            <G_PARTIN_01B_SG7>
                <S_CTA>
                    <D_3139>CN</D_3139>
                    <C_C056>
                        <D_3412>Geosyn Thetics Technologies</D_3412>
                    </C_C056>
                </S_CTA>
                <S_COM>
                    <C_C076>
                        <D_3148>020-38139353</D_3148>
                        <D_3155>TE</D_3155>
                    </C_C076>
                </S_COM>
                <S_COM>
                    <C_C076>
                        <D_3148>NA</D_3148>
                        <D_3155>EM</D_3155>
                    </C_C076>
                </S_COM>
            </G_PARTIN_01B_SG7>
            <G_PARTIN_01B_SG9>
                <S_TOD>
                    <D_4055>6</D_4055>
                    <C_C100>
                        <D_4052>DDP</D_4052>
                    </C_C100>
                </S_TOD>
                <S_LOC>
                    <D_3227>1</D_3227>
                    <C_C517>
                        <D_3224>GUANGDONG</D_3224>
                    </C_C517>
                </S_LOC>
            </G_PARTIN_01B_SG9>
        </G_PARTIN_01B_SG4>
        <S_UNT>
            <D_0074>15</D_0074>
            <D_0062>0010119646</D_0062>
        </S_UNT>
    </M_PARTIN_01B>
    <S_UNZ>
        <D_0036>1</D_0036>
        <D_0020>00000186242603</D_0020>
    </S_UNZ>
</EDIFACTINTERCHANGE>

Did I neglect some config? please suggest, many thanks!

Missing segments in ORDRSP D.96A (openedifact-xsd-libs-96A-1.1-SNAPSHOT.jar file)

Hi,

I downloaded the file openedifact-xsd-libs-96A-1.1-SNAPSHOT.jar from sourceforce and the xsd for ordrsp is missing some segments like SG29 and UNT. Do you know what can be causing it?

Do you have any instructions on how to generate the xsd files using this project? It also seems like almost all fields in the D.96A xsds are defined as numeric even when they are defined as alphanumeric in the spec. Do you know any reason for that?

Testing the new conversion version

Thank you for the new update.

Now if I try to convert from EDIFACT D 96A to XML I get this:

~/.software/edifactconverter> java -cp openedifact-converter/target/openedifact-converter-2.2-SNAPSHOT.jar:openedifact-xsd-libs-01B/target/openedifact-xsd-libs-01B-1.1-SNAPSHOT.jar com.sapstern.openedifact.run.ConverterRunner -process flat -fileIn /tmp/edifact_d_96a_convert_to_xml -ns ns0
org.xml.sax.SAXException: Parsing of UNH failed, no D_0065 found, possible problem with namespaceprefix, check XML
	at com.sapstern.openedifact.sax.EdifactSaxParserToFlat.parse(EdifactSaxParserToFlat.java:213)
	at com.sapstern.openedifact.run.ConverterRunner.main(ConverterRunner.java:34)

If EDI contains arbitory UNA+, parser failed to parse the file

The EDI contains UNA+, but not the key string, please see line 8. The EDI file is:
UNA:+.? ' UNB+UNOX:3+SABICSAP:14+3PL_APAC:14+220830:1923+00000217885470' UNH+0010126665+PARTIN:D:01B:UN' BGM+10+0000000217885470+5' DTM+137:20220830:204' UNS+D' NAD+OY+0010126665++NAGASE PHILIPPINES INTL.::SERVICES CORP.+UNIT 4, 125 NORTH SCIENCE AVENUE,+BINAN, LAGUNA+13+4024+PH' FTX+WHI++MAXPARTIALS+9' FTX+WHI++PARTIALITEM+C' FTX+WHI++TOLOVER+10.0' FTX+WHI++TOLUNDER+10.0' CTA+CN+:NAGASE PHILIPPINES INTL.' COM+25117414:TE' COM+26250085:FX' COM+NA:EM' TOD+6++:::CIF' LOC+1+:::MANILA' UNT+16+0010126665' UNZ+1+00000217885470'

It caused by com.sapstern.openedifact.sax.EdifactSaxParserToXML line 410. please check.

Thanks!

Parser configuration problem: namespace reporting is not enabled

I get the error "Parser configuration problem: namespace reporting is not enabled" on parseEdifact.

I use the sample code from this project:

        InputStream inputStream = Sample01.class.getResourceAsStream("/orders.edi");
        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF8"));
        String contents = in.readLine();
    	EdifactSaxParserToXMLIF theXmlParser = EdifactSaxParserToXML.factory("UTF-8");
    	String edifactXml = theXmlParser.parseEdifact(contents);
        System.out.println(edifactXml);

on the line String edifactXml = theXmlParser.parseEdifact(contents); I got the error.

Here is the Stacktrace:

Okt 06, 2021 1:13:22 PM com.sapstern.openedifact.sax.EdifactSaxParserToXML parse
INFORMATION: xsdFileName EDIFACTINTERCHANGE_ORDERS_97A
Error 
  Error reported by XML parser processing null: Parser configuration problem: namespace
  reporting is not enabled
Error reported by XML parser processing null: Parser configuration problem: namespace reporting is not enabled
net.sf.saxon.trans.XPathException: Error reported by XML parser processing null: Parser configuration problem: namespace reporting is not enabled
	at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:410)
	at net.sf.saxon.event.Sender.send(Sender.java:143)
	at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:46)
	at com.sapstern.openedifact.sax.EdifactSaxParserToXML.parseEdifact(EdifactSaxParserToXML.java:1169)
	at com.sapstern.openedifact.sax.EdifactSaxParserToXML.parseEdifact(EdifactSaxParserToXML.java:1145)
	at de.edi.ProcessorInit.process(ProcessorInit.java:52)
...

What I do wrong? Thank you for any help.

EDIT: I found a strange point. My project is a Maven project and I have the dependency to saxon. If I see right you use sax. But when I use your project as a library, your Project use also saxon.

XML back to EDI

Hello together,

with some fixes I created an xml File with your converter. But if I want to create from this XML-file an EDI file back. To check if is the same as on input. I get this Error:
Parsing of UNH failed, no D_0065 found, possible problem with namespaceprefix, check XML
org.xml.sax.SAXException: Parsing of UNH failed, no D_0065 found, possible problem with namespaceprefix, check XML

Now I see the root Elements has no attributes. Whatever the variable 'isNamespace' has.

Here are the first lines from the generated XML with isNamespace = true. Last Element is UNH:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:EDIFACTINTERCHANGE>
   <ns0:S_UNA>
      <ns0:D_UNA1>:</ns0:D_UNA1>
      <ns0:D_UNA2>+</ns0:D_UNA2>
      <ns0:D_UNA3>.</ns0:D_UNA3>
      <ns0:D_UNA4>?</ns0:D_UNA4>
      <ns0:D_UNA5>*</ns0:D_UNA5>
      <ns0:D_UNA6>'</ns0:D_UNA6>
   </ns0:S_UNA>
   <ns0:S_UNB>
      <ns0:C_S001>
         <ns0:D_0001>UNOC</ns0:D_0001>
         <ns0:D_0002>3</ns0:D_0002>
      </ns0:C_S001>
      <ns0:C_S002>
         <ns0:D_0004>100000</ns0:D_0004>
      </ns0:C_S002>
      <ns0:C_S003>
         <ns0:D_0010>4399902054560</ns0:D_0010>
      </ns0:C_S003>
      <ns0:C_S004>
         <ns0:D_0017>210618</ns0:D_0017>
         <ns0:D_0019>1432</ns0:D_0019>
      </ns0:C_S004>
      <ns0:D_0020>10</ns0:D_0020>
      <ns0:D_0026>KPS designstudio6.5.12.3</ns0:D_0026>
      <ns0:D_0032>EANCOM_ORDER_V2.03</ns0:D_0032>
      <ns0:D_0035>0</ns0:D_0035>
   </ns0:S_UNB>
   <ns0:M_ORDERS_97A>
      <ns0:S_UNH>
         <ns0:D_0062>10</ns0:D_0062>
         <ns0:C_S009>
            <ns0:D_0065>ORDERS</ns0:D_0065>
            <ns0:D_0052>D</ns0:D_0052>
            <ns0:D_0054>97A</ns0:D_0054>
            <ns0:D_0051>UN</ns0:D_0051>
            <ns0:D_0057>EAN007</ns0:D_0057>
         </ns0:C_S009>
      </ns0:S_UNH>
      <ns0:S_BGM>
         <ns0:C_C002>
            <ns0:D_1001>220</ns0:D_1001>

Here are the first lines from the generated XML with isNamespace = false. Last Element is UNH:

<?xml version="1.0" encoding="UTF-8"?>
<EDIFACTINTERCHANGE>
   <S_UNA>
      <D_UNA1>:</D_UNA1>
      <D_UNA2>+</D_UNA2>
      <D_UNA3>.</D_UNA3>
      <D_UNA4>?</D_UNA4>
      <D_UNA5>*</D_UNA5>
      <D_UNA6>'</D_UNA6>
   </S_UNA>
   <S_UNB>
      <C_S001>
         <D_0001>UNOC</D_0001>
         <D_0002>3</D_0002>
      </C_S001>
      <C_S002>
         <D_0004>100000</D_0004>
      </C_S002>
      <C_S003>
         <D_0010>4399902054560</D_0010>
      </C_S003>
      <C_S004>
         <D_0017>210618</D_0017>
         <D_0019>1432</D_0019>
      </C_S004>
      <D_0020>10</D_0020>
      <D_0026>KPS designstudio6.5.12.3</D_0026>
      <D_0032>EANCOM_ORDER_V2.03</D_0032>
      <D_0035>0</D_0035>
   </S_UNB>
   <M_ORDERS_97A>
      <S_UNH>
         <D_0062>10</D_0062>
         <C_S009>
            <D_0065>ORDERS</D_0065>
            <D_0052>D</D_0052>
            <D_0054>97A</D_0054>
            <D_0051>UN</D_0051>
            <D_0057>EAN007</D_0057>
         </C_S009>
      </S_UNH>
      <S_BGM>
         <C_C002>
            <D_1001>220</D_1001>

No need to add a fieldDelimiter for the UNA segment when converting to flat file

In the conversion of a XML to Flat file the UNA is generated with a fieldDelimiter but this is not required for this segment.

For example with this UNA data in the XML:

<S_UNA>
<D_UNA1>:</D_UNA1>
<D_UNA2>+</D_UNA2>
<D_UNA3>.</D_UNA3>
<D_UNA4>?</D_UNA4>
<D_UNA5> </D_UNA5>
<D_UNA6>'</D_UNA6>
</S_UNA>

The generated flat file start with:
UNA+:+.? '
instead of :
UNA:+.? '

To solve this, we could modify code near line 411 in EdifactSaxParserToFlat.java :

            //Beginn des EDI segmentstrings
            if (eName.equals("S_UNA")) {//Abifen*** no fieldDelimiter for UNA segment
                emit(eName.substring(2));
            }
            else {
                emit(eName.substring(2)+fieldDelimiter);
            }
            return;

UNG is not supported

I tried to convert a DESADV with a UNG segment, but it seems like the converter just ignore all the segments within the functional group.

Mojibake issue with character set 'UNOY'

Same issue as last time, while the character set 'UNOY'
input EDI is:

UNA:+.? 'UNB+UNOY:4::7+878542765:1:315000554+91310114786742945M:SAIC+20210927:0933+71073573917223++IFCSUM'UNH+71073573917223+IFCSUM:D:08A:UN'BGM+610+4116356222+9'FTX+AAI+++Goods of chem. Industry'FTX+AAI+++Please mention for further inquiries and accounting?: 4116356222'FTX+AAK+++Please book in accordance to existing freight agreements'FTX+PKG+++AP?: Truck generic'CNT+7:1344.00:KGM'CNT+11:8:C62'CNT+16:2:D97'CNT+19:42.00:KGM'CNT+15:2.792:MTQ'RFF+AHI:4116356222'DTM+171:202109270932:203'RFF+ACE:YE33'RFF+ALZ:264'TDT+20++3+31'DTM+81:20210928:102'FTX+EUR+++Local truck shipment'FTX+TRA+++Street:10'FTX+TRA+++AP?: Truck generic'NAD+CS+2329657:160:86++上海晓荣物流有限公司+嘉定区澄浏中路1228号6幢2层+上海+SHI::86:上海市+201801+CN'CTA+TR'COM+02159907073:TE'COM+02159907073:FX'[email protected]:EM'NAD+CZ+195362:160:86++巴斯夫( ** )有限公司+浦东江心沙路300号+上海市+SHI::86:上海市+200137+CN'CTA+SD+CN61'CTA+TR+A-EDA/GSO:Mrs ZHENG Ying Jasrine'COM+?+86212039:TE'[email protected]:EM'NAD+FP+195362:160:86++巴斯夫( ** )有限公司+浦东江心沙路300号+上海市+SHI::86:上海市+200137+CN'EQD+CN+1064824613'CNI+1+6210802264'DTM+63:20211002:102'DTM+63:08301730:501'CNT+11:8:PCE'CNT+29:1200.00:KGM'CNT+7:1344.00:KGM'CNT+16:2:D97'CNT+99:42.00:KGM'TOD+5++DDP'LOC+1+:::TIANJIN'NAD+CN+2821548:160:86+东丽区+北京美扬时代科贸有限公司+荣明达物流金钟路金钟工业园区金发道3号路+天津+TJN::86:天津市+300163+CN'CTA+CN+:天津荣明达物流'COM+15332112687:TE'GID+1+2:CP3:67:91:Pallet,wood,CP3,1140x1140x138mm,HT+8:1A1:67:91:钢桶'PIA+5+55713536:SA'PIA+5+3208909010:HS'PIA+1+YAP00019 GC DG'FTX+AAA+++埃夫卡® SI 2040 消泡剂 150KG Metal-Drum, non rem.hd. 1A1'FTX+PAC+++Pallet, wood, CP3, 1140x1140x138mm, HT'FTX+AHF+++ED2'NAD+PW+7C61/WH15:160:86'NAD+WQ+++RA'MEA+WT+AAL+KGM:1200.000'MEA+WT+AAE+KGM:1344.000'MEA+WT+WT+KGM:42.000'MEA+TE+TC:::Flash Point+CEL:49.00'DIM+3+MMT:1170.0:1170.0:1020.0'RFF+LI:6210802264:000010'RFF+VN:6009402806:000020'RFF+OP:20210402006'RFF+UC:20210402006'DTM+4:20210402:102'RFF+SF:7C61:WH15'DTM+181:202109280000:203'DTM+200:073000163000:502'DGS+ADR+3+1993+49.0:CEL+3+++++3'FTX+AAD+++**道路运输危险货物信息 UN 1993, 正式运输名称: 易燃液体,未另作规定的 ( 2,6-二甲基庚烷-4-酮, 溶剂 石脑油), 类别或项别 3, 包装类别 III'DGS+TEC'FTX+ACB+++Odor?: 特有的'FTX+AAN+++Suitable Materials For Packages?: 耐热漆 RDL 50, 耐热漆 R 78433, 烤干漆(Stove-lacquer AV500), 玻璃, 高密度聚乙烯, 碳钢(铁), 氟化高密度聚乙烯'UNT+73+71073573917223'UNZ+1+71073573917223'

Please help to check, thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.