Version Converter between EPCIS 2.0 and 1.2
OpenEPCIS solution to convert EPCIS XML document from version 1.2 to 2.0 and vice versa.
Quick Links
The following resources cover the XSL version transformer that GS1 publishes and the OpenEPCIS version converter as web application, API and source code:
- GS1 publication of the XSL version transformer: https://ref.gs1.org/tools/epcis/xsl/
- Version converter web application: https://tools.openepcis.io/ui/format-converter
- Version converter API endpoint: https://tools.openepcis.io/q/swagger-ui/#/Format%20Converter
- Version converter application code: https://github.com/openepcis/openepcis-document-converter
Introduction
EPCIS 2.0 introduces several attributes that EPCIS 1.2 does not have: the How dimension for sensor data, the AssociationEvent event type and the persistentDisposition property. It also removes the <extension> wrappers in which EPCIS 1.2 nested the attributes that arrived later in the 1.x lifecycle. Whether you migrate existing EPCIS 1.2 data to 2.0 or accept EPCIS 2.0 traffic from partners while your downstream systems still expect 1.2, you need a converter that handles these structural differences correctly.
The open-source OpenEPCIS version converter is based on XSLT and handles the standard EPCIS 1.2 ↔ 2.0 XML round trip for typical event structures. For migrations at production volume, such as 1.2 exports of several gigabytes, deep extension trees or mixed 1.2 and 2.0 batches, the Business edition adds a SAX-streaming converter.
Usage
You can convert an EPCIS XML document between 1.2 and 2.0 in the browser, through the API or from the command line.
Web Application
The web application takes an EPCIS XML document in version 1.2 or 2.0 and returns it in the other version. It is available here.
API Endpoint
The version converter API accepts an EPCIS document and returns the converted document in its response. You can call it from your own application's code or try it online through Swagger-UI, which is available here.
Command Line
cURL (Client URL) is a widely used command-line tool for sending data to a server and receiving its response, and many developers prefer it to a web interface. To convert an XML document with cURL, post it to
https://tools.openepcis.io/api/convert/version/1.2 or https://tools.openepcis.io/api/convert/version/2.0, depending on the target version. The following request converts an EPCIS 1.2 XML document to 2.0 XML:
curl -X 'POST' \
'https://tools.openepcis.io/api/convert/version/2.0' \
-H 'accept: application/xml' \
-H 'Content-Type: application/xml' \
-d '<?xml version="1.0" encoding="UTF-8"?>
<epcis:EPCISDocument xmlns:epcis="urn:epcglobal:epcis:xsd:1" schemaVersion="1.2"
creationDate="2005-07-11T11:30:47.0Z">
<EPCISBody>
<EventList>
<ObjectEvent>
<eventTime>2005-04-04T20:33:31.116-06:00</eventTime>
<eventTimeZoneOffset>-06:00</eventTimeZoneOffset>
<epcList>
<epc>urn:epc:id:sgtin:0614141.107346.2018</epc>
</epcList>
<action>OBSERVE</action>
<extension>
<extension>
<sensorElementList>
<sensorElement>
<sensorMetadata time="2021-05-27T13:50:00.000+01:00"/>
<sensorReport type="gs1:MT-Length" component="Northing" value="-477979.89" uom="MTR"
coordinateReferenceSystem="http://www.opengis.net/def/crs/EPSG/0/27700"/>
</sensorElement>
</sensorElementList>
</extension>
</extension>
<example:myField xmlns:example="http://ns.example.com/epcis">Example of a vendor/user extension</example:myField>
</ObjectEvent>
</EventList>
</EPCISBody>
</epcis:EPCISDocument>'
Application Code
The converter is written in Java and uses Apache Xalan. Its code is published on the OpenEPCIS GitHub account, where you can read it directly or use it as a dependency in your own projects. The complete code is available here.
Converting EPCIS 1.2 XML to 2.0 XML
To convert an EPCIS 1.2 XML document to EPCIS 2.0 XML, pass the document as an InputStream to the conversion
method of VersionTransformer.class:
final InputStream inputDocument = getClass().getResourceAsStream("/version/Epcis_1_2.xml");;
final VersionTransformer versionTransformer = new VersionTransformer();
final Conversion conversion = Conversion.builder()
.generateGS1CompliantDocument(false)
.fromMediaType(EPCISFormat.XML)
.fromVersion(EPCISVersion.VERSION_1_2_0)
.toMediaType(EPCISFormat.XML)
.toVersion(EPCISVersion.VERSION_2_0_0)
.build();
final InputStream convertedDocument = versionTransformer.convert(inputDocument,conversion);
//System.out.println("Converted XML 2.0 document : " + IOUtils.toString(convertedDocument,StandardCharsets.UTF_8));
Converting EPCIS 2.0 XML to 1.2 XML
To convert an EPCIS 2.0 XML document to EPCIS 1.2 XML, pass the document as an InputStream to the conversion
method of VersionTransformer.class:
final InputStream inputDocument = getClass().getResourceAsStream("/version/Epcis_2_0.xml");;
final VersionTransformer versionTransformer = new VersionTransformer();
final Conversion conversion = Conversion.builder()
.generateGS1CompliantDocument(false)
.fromMediaType(EPCISFormat.XML)
.fromVersion(EPCISVersion.VERSION_2_0_0)
.toMediaType(EPCISFormat.XML)
.toVersion(EPCISVersion.VERSION_1_2_0)
.build();
final InputStream convertedDocument = versionTransformer.convert(inputDocument, conversion);
//System.out.println("Converted XML 1.2 document : " + IOUtils.toString(convertedDocument,StandardCharsets.UTF_8));