DEV Community

Stock Trends with Joe
Stock Trends with Joe

Posted on

Parsing X12 850 Purchase Orders in Java with OBOE

No heavy commercial EDI engines required.

If you’ve ever worked with EDI in Java, you know the pain: massive commercial libraries, hundreds of generated classes, or writing your own fragile parser from scratch.

OBOE (Open Business Objects for EDI) changes that.

It’s a mature, lightweight, pure-Java library that uses simple XML message definition files to describe any EDI transaction — including the popular X12 850 Purchase Order.

In this article, I’ll show you exactly how to parse a real X12 850 document in under 30 lines of code using OBOE v2.0.0 (now available on Maven Central).

Why OBOE?

  • Pure Java (no native dependencies)
  • XML-driven rules → extremely extensible
  • Built-in code generator + GUI editor
  • Supports X12, EDIFACT, TRADACOMS, and HIPAA
  • Battle-tested for over 25 years
  • Zero-cost and now officially on Maven Central

Step 1: Add OBOE to Your Project

<dependency>
    <groupId>io.github.ediandxml</groupId>
    <artifactId>OBOE</artifactId>
    <version>2026.04.08</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure OBOE (oboe.properties)

Create a file named oboe.properties in src/main/resources/:

xmlPath=xml/
searchClassPathForMessageFiles=true
Enter fullscreen mode Exit fullscreen mode

Step 3: The Parsing Code

Here’s a complete, working example that parses a real X12 850 Purchase Order:

import io.github.ediandxml.oboe.*;
import java.io.*;
import java.util.Properties;

public class ParseX12850Example {

    public static void main(String[] args) throws Exception {

        // 1. Load OBOE properties from classpath
        Properties props = new Properties();
        try (InputStream is = ParseX12850Example.class.getClassLoader()
                .getResourceAsStream("oboe.properties")) {
            props.load(is);
        }

        // 2. Load the XML message definition for 850
        String transactionXml = "test.X12.ts.xml";   // or your custom 850 definition

        // 3. Create the parser
        EDIXMLParser parser = new EDIXMLParser();
        parser.setProperties(props);

        // 4. Load your 850 EDI document
        String edi850 = new String(java.nio.file.Files.readAllBytes(
                new java.io.File("testFiles/5-850.x12").toPath()));

        // 5. Parse it!
        X12Envelope envelope = (X12Envelope) parser.parse(edi850, transactionXml);

        // 6. Navigate the document
        TransactionSet ts = envelope.getTransactionSet(0);

        System.out.println("PO Number: " + ts.getSegment("BEG").getElementValue(3));
        System.out.println("PO Date:   " + ts.getSegment("BEG").getElementValue(5));
        System.out.println("Buyer:     " + ts.getSegment("N1", "BY").getElementValue(2));

        // Loop through PO1 detail lines
        for (int i = 0; i < ts.getLoopCount("PO1"); i++) {
            Segment po1 = ts.getLoop("PO1", i).getSegment("PO1");
            System.out.printf("Line %d - Qty: %s, Price: %s, Part: %s%n",
                    i + 1,
                    po1.getElementValue(2),
                    po1.getElementValue(4),
                    po1.getElementValue(6));
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

What Just Happened?

OBOE used the XML rules file to understand the full structure of the 850, handled envelopes, delimiters, and gave you clean access to every segment and loop.

Try It Yourself

  1. Clone the repo: git clone https://github.com/EDIandXML/OBOE.git
  2. Add the Maven dependency
  3. Drop in the code above
  4. Run it against any 850 file

GitHub logo EDIandXML / OBOE

Open Business Objects For EDI

OBOE - Open Business Objects for EDI

Java Maven License

OBOE is a lightweight, mature, and flexible Java library for parsing, validating, and generating Electronic Data Interchange (EDI) documents.

It fully supports:

  • ANSI X12 (4010, 5010, and many others)
  • UN/EDIFACT
  • TRADACOMS
  • HIPAA transactions (837, 835, 834, 270/271, etc.)

OBOE uses simple XML-based message definition files (rules files) to define the structure of each transaction set. This makes it extremely extensible without hard-coding formats.


✨ Features

  • Pure Java — no heavy commercial EDI engines required
  • XML-driven rules engine (ediRules.xsd)
  • Built-in code generator that creates strongly-typed Java classes
  • Graphical Message Editor (Util.TransactionSetMessageEditor)
  • Support for envelopes (ISA/GS/ST, UNB/UNH, etc.)
  • Robust error handling and validation
  • Lightweight with minimal dependencies
  • 25+ years of real-world EDI battle-testing

🚀 Recent Updates (2025–2026)

  • Package name migrated from americancoders.comio.github.EDIandXML
  • Repository cleaned up and modernized on GitHub
  • Improved build process (Maven-ready)
  • Better documentation and community readiness

📦

Maven Central: io.github.ediandxml:OBOE:2026.04.08

Top comments (0)