Examples of using EDIReader

We provide several Java programs to illustrate the use of EDIReader and let you quickly try it out on your own EDI data. These programs are included in the product downloads, but are provided here in source form for convenience. The downloaded versions may have revisions not reflected below. In each case, the programs were written to be simple tutorial examples that you may use as-is or easily modify for your own purposes.

EDITransform – XSLT stylesheet applied directly to EDI input

The program is basically a textbook example of a Java program that uses an XSLT stylesheet to transform source data parsed with a SAX parser except for one thing: instead of using a typical SAX parser, such as the one Sun distributes with their J2SE, this program uses EDIReader as its SAX parser.

Here is a simple stylesheet you can use to try it out on your own EDI data. Or here is an example ANSI X12 purchase order you can use as input, and the simple HTML page produced by this stylesheet.

EDItoXML – Parsed EDI captured as XML

This program is even simpler than the one above. It uses an XSLT processor without a stylesheet, taking advantage of the default behavior of producing XML output corresponding to the parsed input. This is a useful tool to provide a concrete XML file for use while developing stylesheets.

Here is the output produced for the ANSI X12 purchase order we used above. An example of an EDIFACT purchase order produces this XML output.

Transaction set plugin to provide segment looping structure

To illustrate the effect of a transaction set plugin on generated XML, consider this ANXI X12 interchange containing an 837 transaction set, a Health Care Claim used in HIPAA scenarios. As in the previous example, EDItoXML performs a conversion to XML.

The EDIPlugins.jar file downloadable from SourceForge contains a plugin for the 837 transaction set. When this jar file is added to the CLASSPATH, the otherwise unchanged EDItoXML run produces this enhanced XML output for the same 837 input. Notice the introduction of nested loop elements with Id attributes corresponding to the loop names published in the ANSI X12 specification, making it easier to transform the data with XSLT.

EDIScanner – EDIReader used with a custom ContentHandler

This program demonstrates EDIReader as an embedded EDI parser coupled with a custom “back end” ContentHandler implemented as an inner class.

Formatter – Formatted listing of EDI data

This formatted output was produced by the Formatter utility. In this example, a plugin was provided for the ANSI 835 document which allows the Formatter to display nested segment groupings. An example using an EDIFACT MSCONS message is here. Note that the segments are presented in a line-oriented manner regardless of the segment terminators that appear in the raw EDI data.

EDIAck – Generate functional acknowledgment

Functional acknowledgments are used in many ANSI X12 scenarios and allow an EDI recipient to notify the sender that EDI structures were successfully parsed at the recipient's site. The form of notification is itself an EDI document. The EDIAck program demonstrates how to use EDIReader to generate such acknowledgments.

Notice that the use of segment terminators in the generated EDI output are the same as those in the EDI input. Therefore, if you are using EDIReader to generate acknowledgments for various trading partners, each one will receive EDI acknowledgments with the terminator conventions they prefer.