Getting Started with EDIFACT Translation

Requirements:
IP*Works! EDI

Introduction

The IP*Works! EDI suite includes components for reading, writing, and translating EDIFACT documents, as well as the transmission of secure transactions over the Internet. This article will focus on using the EDITranslator component to translate from EDIFACT to XML and also from XML to EDIFACT.

Contents

  1. Converting EDIFACT to XML
  2. Converting XML to EDIFACT

Converting EDIFACT to XML

The EDITranslator component is designed to convert EDIFACT documents to XML and vice versa. The steps below demonstrate the typical process for these conversions. This guide will not cover all possible functionality the EDITranslator component providses, so please consule the help document for additional options and details.

Quick Example

The following sections discuss the details of how EDIFACT documents can be translated to XML. The following sample code will be used as a basis for discussing these options.

EDITranslator1.SchemaFormat = EditranslatorSchemaFormats.schemaJSON;
EDITranslator1.InputFormat = EditranslatorInputFormats.ifEDIFACT;
EDITranslator1.OutputFormat = EditranslatorOutputFormats.ofXML;
EDITranslator1.LoadSchema("C:\\schemas\\RSSBus_D09B_ORDERS.json");
EDITranslator1.InputFile = myEDIFile;

//EDI -> XML
EDITranslator1.Translate();
string translatedXML = EDITranslator1.OutputData;

//XML -> EDI
EDITranslator1.Reset();
EDITranslator1.InputFormat = EditranslatorInputFormats.ifXML;
EDITranslator1.OutputFormat = EditranslatorOutputFormats.ofEDIFACT;
EDITranslator1.InputData = translatedXML;
EDITranslator1.Translate();

string translatedEDI = EDITranslator1.OutputData;

Loading an EDI Schema

To begin, it is recommended to provide an EDI schema that describes the EDIFACT document being translated. This is not required, but it does allow details such as proper element names and descriptive details to be included in the translated XML.

If you do not already have a set of schemas the RSSBus JSON schemas (http://www.rssbus.com/schemas/) may be used.

The component supports the following schema formats:

In this article we will use a D09B ORDERS message with a Altova schema. To load the schema call the LoadSchema method. For instance:

EDITranslator1.SchemaFormat = EditranslatorSchemaFormats.schemaJSON;
EDITranslator1.LoadSchema("C:\\schemas\\RSSBus_D09B_ORDERS.json");

Renaming Rules

The EDITranslator component optionally supports renaming EDI elements when translating to XML. By default the XML element names will be automatically determined by the component from the EDIFACT document and schema. For instance:

EDIFACT data

UNA:+.? '
UNB+UNOA:2+MGATE1:65+TESTER:65+020508:1413+0709210008' 
UNH+1+ORDERS:D:09B:UN:1.1'
BGM+E40+MKIDI5422'
DTM+137:199904081315:203'
DTM+203:20110408:102'
DTM+Z02:20110408:203'
DTM+273:201011:610'
...

Translated to XML without renaming:

<Interchange>
<Meta>
<UNB1 type="Composite"><Component>UNOA</Component><Component>2</Component></UNB1>
<UNB2 type="Composite"><Component>MGATE1</Component><Component>65</Component></UNB2>
<UNB3 type="Composite"><Component>TESTER</Component><Component>65</Component></UNB3>
<UNB4 type="Composite"><Component>020508</Component><Component>1413</Component></UNB4>
<UNB5>0709210008</UNB5>
</Meta>
<TransactionSet>
<Meta>
<F0062 desc="MESSAGE REFERENCE NUMBER">1</F0062>
<S009 type="Composite" desc="MESSAGE IDENTIFIER"><Component>ORDERS</Component><Component>D</Component><Component>09B</Component><Component>UN</Component><Component>1.1</Component></S009>
</Meta>
<BGM type="Segment" desc="BEGINNING OF MESSAGE">
<C002 type="Composite" desc="DOCUMENT/MESSAGE NAME"><Component>E40</Component></C002>
<C106 type="Composite" desc="DOCUMENT/MESSAGE IDENTIFICATION"><Component>MKIDI5422</Component></C106>
</BGM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<C507 type="Composite" desc="DATE/TIME/PERIOD"><Component>137</Component><Component>199904081315</Component><Component>203</Component></C507>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<C507 type="Composite" desc="DATE/TIME/PERIOD"><Component>203</Component><Component>20110408</Component><Component>102</Component></C507>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<C507 type="Composite" desc="DATE/TIME/PERIOD"><Component>Z02</Component><Component>20110408</Component><Component>203</Component></C507>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<C507 type="Composite" desc="DATE/TIME/PERIOD"><Component>273</Component><Component>201011</Component><Component>610</Component></C507>
</DTM>
...

For convenience of the entity consuming the XML data the EDI elements can be renamed when converting to XML. Renaming rules take the format EDIName:XMLName. For instance

//Define renaming rules
EDITranslator1.AddRenamingRule("F0062:MessageRefNum);
EDITranslator1.AddRenamingRule("C507:DateTimePeriod");

The above code will result in XML that is translated with renaming.

lang='csharp'>
<Interchange>
<Meta>
<UNB1 type="Composite"><Component>UNOA</Component><Component>2</Component></UNB1>
<UNB2 type="Composite"><Component>MGATE1</Component><Component>65</Component></UNB2>
<UNB3 type="Composite"><Component>TESTER</Component><Component>65</Component></UNB3>
<UNB4 type="Composite"><Component>020508</Component><Component>1413</Component></UNB4>
<UNB5>0709210008</UNB5>
</Meta>
<TransactionSet>
<Meta>
<MessageRefNum desc="MESSAGE REFERENCE NUMBER">1</MessageRefNum>
<S009 type="Composite" desc="MESSAGE IDENTIFIER"><Component>ORDERS</Component><Component>D</Component><Component>09B</Component><Component>UN</Component><Component>1.1</Component></S009>
</Meta>
<BGM type="Segment" desc="BEGINNING OF MESSAGE">
<C002 type="Composite" desc="DOCUMENT/MESSAGE NAME"><Component>E40</Component></C002>
<C106 type="Composite" desc="DOCUMENT/MESSAGE IDENTIFICATION"><Component>MKIDI5422</Component></C106>
</BGM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<DateTimePeriod type="Composite" desc="DATE/TIME/PERIOD"><Component>137</Component><Component>199904081315</Component><Component>203</Component></DateTimePeriod>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<DateTimePeriod type="Composite" desc="DATE/TIME/PERIOD"><Component>203</Component><Component>20110408</Component><Component>102</Component></DateTimePeriod>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<DateTimePeriod type="Composite" desc="DATE/TIME/PERIOD"><Component>Z02</Component><Component>20110408</Component><Component>203</Component></DateTimePeriod>
</DTM>
<DTM type="Segment" desc="DATE/TIME/PERIOD">
<DateTimePeriod type="Composite" desc="DATE/TIME/PERIOD"><Component>273</Component><Component>201011</Component><Component>610</Component></DateTimePeriod>
</DTM>

As seen above the XML now contains friendly element names as defined by the renaming rule. To highlight this:

No Renaming:
<F0062 desc="MESSAGE REFERENCE NUMBER">1</F0062>

Renaming rule "F0062:MessageRefNum":
<MessageRefNum desc="MESSAGE REFERENCE NUMBER">1</MessageRefNum>

Renaming rules can also be saved and loaded by calling SaveRenamingRules and LoadRenamingRules.

Translating to XML

In order to translate from EDIFACT to XML, the InputFormat must be set to inform the EDITranslator component of the type of data being provided. In this case, this property should be set to EditranslatorInputFormats.ifEDIFACT. You must also instruct the component on the output format, which in this case will be EditranslatorOutputFormats.ofXML. After these options are configured, translating is as simple as calling the Translate method. EDI data can be read from a string, a file on disk, or a stream. Likewise, the output data can be saved to a string, a file on disk, or a stream. Please refer to the Quick Sample section for a code example.

After translating the EDIFACT data to XML you may optionally call ExportXMLSchema. This method outputs a XML schema (.xsd) which can be helpful when constructing XML messages outside of the component which can later be translated back to EDIFACT.

Converting XML to EDIFACT

To translate XML to EDIFACT, specify the XML input, set InputFormat to indicate that the input is XML, select the OutputFormat type, and call the Translate method. The EDI schema is not required.

The InputFormat property must be set to EditranslatorInputFormats.ifXML. This value tells the component to translate from XML. Similarly, the OutputFormat must be set to EditranslatorOutputFormats.ofEDIFACT to instruct the component to format the output as EDIFACT data.

//XML -> EDIFACT
EDITranslator1.Reset();
EDITranslator1.InputFormat = EditranslatorInputFormats.ifXML;
EDITranslator1.OutputFormat = EditranslatorOutputFormats.ofEDIFACT;
EDITranslator1.InputData = translatedXML;

EDITranslator1.Translate();

string translatedEDIFACT = EDITranslator1.OutputData;


We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.