我应该如何从 835 EDI 文件中提取数据?

How shall i extract data from 835 EDI file?

我有 835 个 EDI 文件,

ISA*00*          *00*          *33*83876          *ZZ*B00482000   *190128*1100*^*00501*000000001*0*T*:~
ST*835*000000001~
BPR*H*0*C*NON************20190128~
TRN*1*PK673981180*141138499245*PS0087726~
REF*EV*B048499999800~
REF*F2*1083~
DTM*405*20190128~

我该如何提取 ST 值,即 000000001 等等,

我尝试先使用 SMOOKS 将我的 edi 文件转换为 XML 格式,然后通过父节点和子节点检索数据。

  public static void main(String[] args) throws SmooksException, Exception {
    String modelURI = "urn:org.milyn.edi.unedifact:d99a-mapping:1.4";
    UNEdifactInterchangeParser parser = new UNEdifactInterchangeParser();
 //   parser.addMappingModels(modelURI, new URI("/"));
    parser.setFeature(EDIParser.FEATURE_IGNORE_NEWLINES, true);
    SAXHandler handler = new SAXHandler();
    parser.setContentHandler(handler);
    parser.parse(new InputSource(new java.io.FileInputStream(
            "myEDIfile.edi")));
    Document doc = handler.getDocument();
    // Here you have your document
    new XMLOutputter(Format.getPrettyFormat()).output(doc, System.out);
}

但我遇到了错误

引起:org.xml.sax.SAXException:Unknown/UnexpectedUN/EDIFACT控制块段代码'ISA'.

如果有人能帮助我找到可能的解决方案,那就太好了。 提前致谢..

看看 X12 解析器 - 它通常用于此类文件:

文档:https://media.readthedocs.org/pdf/x12-parser/latest/x12-parser.pdf

GitHub 回购:https://github.com/imsweb/x12-parser

您正在尝试使用 EDIFACT 解析器解析 X12 835。

您需要使用相应的 X12 解析器,而不是 UNEdifactInterchangeParser。

看看 edi-835-parser。这是我专门为解析 EDI 835 文件类型而编写的 Python 库,比使用 x12-parser 'out-of-the-box' 更好。

GitHub 回购:https://github.com/keironstoddart/edi-835-parser.