Skip to content

Reading EDI Data (Configuration)

Michael Edgar edited this page Jul 3, 2022 · 7 revisions

This article assumes the reader has basic knowledge of EDI structures and terminology

EDIStreamReader Configuration

The EDIStreamReader can be configured using several properties (set on the EDIInputFactory) to modify the reader's behavior.

// Create an EDIInputFactory
EDIInputFactory factory = EDIInputFactory.newFactory();
factory.setProperty(EDIInputFactory.EDI_VALIDATE_CONTROL_CODE_VALUES, false);

// Obtain an InputStream of the EDI document to read.
InputStream stream = new FileInputStream(...);

// Create an EDIStreamReader from the stream using the factory
EDIStreamReader reader = factory.createEDIStreamReader(stream);

// Continue processing with the reader...
  1. EDI_VALIDATE_CONTROL_STRUCTURE
  2. EDI_VALIDATE_CONTROL_CODE_VALUES
  3. XML_DECLARE_TRANSACTION_XMLNS
  4. EDI_IGNORE_EXTRANEOUS_CHARACTERS
  5. JSON_NULL_EMPTY_ELEMENTS
  6. JSON_OBJECT_ELEMENTS
  7. XML_USE_SEGMENT_IMPLEMENTATION_CODES

Disable Validation of Control Structures

Out of the box, instances of EDIStreamReader will validate the control structures of X12 and EDIFACT messages (interchange, group, and transaction headers and trailers).

If you wish to disable the validation of control the structure, including field sizes and types, set the EDIInputFactory.EDI_VALIDATE_CONTROL_STRUCTURE property to false on an instance of EDIInputFactory prior to creating a new EDIStreamReader.

Disable Validation of Control Codes

Out of the box, instances of EDIStreamReader will validate the control structures of X12 and EDIFACT messages (interchange, group, and transaction headers and trailers). This validation includes checking that some fields contain one of an enumerated list of values (e.g. a known transaction set code in X12 segment ST, element 1).

If you wish to disable the validation of the code values but keep the validation of the structure, including field sizes and types, set the EDIInputFactory.EDI_VALIDATE_CONTROL_CODE_VALUES property to false on an instance of EDIInputFactory prior to creating a new EDIStreamReader, as shown below.

Declare XML Namespaces on TRANSACTION element

When using the XMLStreamReader produced by StAEDI's EDIInputFactory, this property will generate the StAEDI XML namespace attributes on the TRANSACTION element. The namespaces are declared in the EDINamespaces class. This behavior may be desirable when reading EDI-as-XML and you wish to split the resulting XML data into separate files, one per transaction, and still keep track of the XML namespaces.

Ignore Extraneous Characters

Since: 1.13
Default: false
When set to true, non-graphical, control characters will be ignored in the EDI input stream when not used as delimiters. This includes characters ranging from 0x00 through 0x1F and 0x7F.

Treat Empty Elements as JSON Null

Since: 1.14
Default: false
When set to true, simple data elements not containing data will be represented via the JSON parsers as a null value.

Simple Elements as JSON Objects

Since: 1.14
Default: false
When set to true, simple data elements will be represented via the JSON parsers as JSON objects. When false, simple elements will be JSON primitive values (string, number) in the data array of their containing structures.

Use Segment Implementation Codes as XML Elements

Since: 1.21
Default: false
When set to true, the XML elements representing segments in an EDI implementation schema will be named according to the schema-defined code attribute for the segment.

Alternate Character Encoding

By default, StAEDI will read EDI input using the UTF-8 standard character set. The character set may be overridden by creating an instance of EDIStreamReader (via EDIInputFactory) with the name of an alternate Charset. Names of Charsets that return true for a call to Charset#isSupported may be used.