Git Product home page Git Product logo

edifact-xml's Introduction

Edifact XML Converter for Java

The Applied Models Edifact to XML converter for Java parses any Edifact input and outputs XML according to the ISO/TS 20625 standard. The converter implements the org.xml.sax.XMLParser interface, which means that it is easily integrated with standard xml processing tools. This implementation covers all Edifact directories from 88.1 up to D11A.

Speed and simplicity

The converter is extremely fast and very simple to use. No configuration is needed. It can easily handle many thousands of messages per second on standard hardware. See below for some examples of use.

License

The Edifact-XML converter is licensed under GPL v3.0

Contact

info(at)appliedmodels.com

XMLWriter example

This example uses the Apache Commons XMLWriter class to output the XML the console.

import java.io.Writer;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.apache.ws.commons.serialize.XMLWriter;
import org.apache.ws.commons.serialize.XMLWriterImpl;
import com.appliedmodels.edifact.parser.EdifactParser;

public class EdifactTest {

    public static void main(String args[]) throws Exception {
        Writer out=new OutputStreamWriter(System.out);
        try {
            XMLReader edifactParser=new EdifactParser();
            XMLWriter handler=new XMLWriterImpl();
            handler.setWriter(out);
            edifactParser.setContentHandler(handler);
            edifactParser.parse(new InputSource(new FileReader("/tmp/test.edi")));
        }
        finally {
            out.flush();
            out.close();
        }
    }
}

XPath example

This example shows how to use XPath to process the XML Edifact.

import com.appliedmodels.edifact.parser.EdifactParser;
import java.io.FileReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

/*
 * 2010 Applied Models Ltd
 * All rights reserved.
 */
public class EdifactXPathTest {

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

        XMLReader edifactParser=new EdifactParser();

        //create a SAX source
        InputSource inputSource=new InputSource(new FileReader("/tmp/test.edi"));
        SAXSource saxSource=new SAXSource(edifactParser, inputSource);
    
        //obtain a DOM tree
        DOMResult domResult=new DOMResult();
        TransformerFactory transformerFactory=TransformerFactory.newInstance();
        transformerFactory.newTransformer().transform(saxSource, domResult);

        //evaluate an XPath that extracts all free text elements
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression xpathExpr = xpath.compile("//S_FTX/C_C108/D_4440/text()");

        Object result = xpathExpr.evaluate(domResult.getNode(), XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;
        for (int i = 0; i < nodes.getLength(); i++) {
            System.out.println(nodes.item(i).getNodeValue());
        }
    }
}

edifact-xml's People

Contributors

coolid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.