【问题标题】:EDIFACT files comparison using Java使用 Java 比较 EDIFACT 文件
【发布时间】:2018-07-31 13:07:33
【问题描述】:

我想比较两个 edifact 文件并找出它们之间的差异以及使用 java。请建议代码。附上Edifact的示例文件..

UNB+UNOA:1+005435656:1+006415160:1+060515:1434+00000000000778'
UNH+00000000000117+INVOIC:D:97B:UN'
BGM+380+342459+9'
DTM+3:20060515:102'
RFF+ON:521052'
NAD+BY+792820524::16++CUMMINS MID-RANGE ENGINE PLANT'
NAD+SE+005435656::16++GENERAL WIDGET COMPANY'
CUX+1:USD'
LIN+1++157870:IN'
IMD+F++:::WIDGET'
QTY+47:1020:EA'
ALI+US'
MOA+203:1202.58'
PRI+INV:1.179'
LIN+2++157871:IN'
IMD+F++:::DIFFERENT WIDGET'
QTY+47:20:EA'
ALI+JP'
MOA+203:410'
PRI+INV:20.5'
UNS+S'
MOA+39:2137.58'
ALC+C+ABG'
MOA+8:525'
UNT+23+00000000000117'
UNZ+1+00000000000778'

【问题讨论】:

  • github.com/metormote/edifact-xml ,有比 EDIFACT 更多的 XML 实用程序 ...
  • 您可以从使用基于Eugene W. Myers 算法的差异工具开始。您将获得一组包含两个文档相同和不同部分的蛇。由于 EDIFACT 文档通常包含相同的段集,因此差异比较应该会产生足够的结果。您可能会稍微调整算法以忽略大小写变化和类似的东西。

标签: java edifact


【解决方案1】:

这太痛苦了,无法尝试吸收。我建议使用图书馆。谷歌是你的朋友。 This one is literally Google code

但是多年的经验也告诉我,您并没有解决 END 问题。一旦你让你的文本比较工作,你就会陷入它区分大小写的事实。一旦你克服了这一点,你就会意识到 EDI 属性不是特定于订单的。解决这个问题,然后您才会知道客户不仅想知道文档是否相同,还想知道它们有什么不同IN EDI TERMS

我强烈建议您删除此内容并转向完全不同的方向。有许多可用的开源 EDI 解析器。通过它们运行 Edifact 文档。则支持两种模式:A Summary of equivalence;并详细报告是什么让它们与众不同。

您现在所做的事情会容易得多,只需执行 MD5 校验和即可判断文件是否相同。

【讨论】:

    【解决方案2】:

    这是我正在做的事情,但它实际上并没有给我一个正确的模式:

    import java.io.*;
    import java.util.*;
    
    
    public class Compare_EDIFiles
    {
    
     public static void main (String[] args) throws java.io.IOException
        {
    
         //Getting the name of the files to be compared.
    
         FileReader fis1 = new FileReader ("filename1");
         FileReader fis2 = new FileReader ("filename2);
    
        String s1="";
        String s2="",s3="",s4="";
        String y="",z="";
    
        //Reading the contents of the files
    
        BufferedReader br = new BufferedReader (fis1);
        BufferedReader br1 = new BufferedReader (fis2);
    
       while((z=br1.readLine())!=null)
        s3+=z;
    
      while((y=br.readLine())!=null)
         s1+=y;
    
      System.out.println ();
    
         //String tokenizing
    
        int numTokens = 0;
        //String delim = ":";
        //String delim1 = ":";
        StringTokenizer st = new StringTokenizer (s1);
        String[] a = new String[10000];
        for(int l=0;l<10000;l++)
    
          {
            a[l]="";
          }
        int i=0;
        while (st.hasMoreTokens())
          {
            s2 = st.nextToken();
            a[i]=s2;
            i++;
            numTokens++;
          }
    
         int numTokens1 = 0;
         StringTokenizer st1 = new StringTokenizer (s3);
         String[] b = new String[10000];
         for(int k=0;k<10000;k++)
    
          {
             b[k]="";
          }
         int j=0;
         while (st1.hasMoreTokens())
           {
            s4 = st1.nextToken();
            b[j]=s4;
            j++;
            numTokens1++;
           }
    
    //comparing the contents of the files and printing the differences, if any.
      int x=0;
          for(int m=0;m<a.length;m++)
          {
       if(a[m].equals(b[m])){}
        else
        {
         x++;
      System.out.println(a[m] + " -- " +b[m]);
      System.out.println();}
          }
     System.out.println("No. of differences : " + x);
     if(x>0){System.out.println("Files are not equal");}
     else{System.out.println("Files are equal. No difference found");}
    
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多