Example: Converting a Custom EDI Message Type with DataDirect XML Converters™

In this simple example, you'll see how to specify a custom EDI message type so that properietary EDI formats can be understood and converted to XML using DataDirect XML Converters™.


The Problem

General Anodyne Enterprises, Ltd. uses a legacy EDI system to record and transmit corporate data, and they now wish to use XML so they can communicate and work with data more easily across the enterprise. Unfortunately, they use a variant of the EDIFACT NAD (Name and Address) C059 composite element, so their EDI does not comply with the published standard, which is shown in the following table from the Stylus Studio web site.

Use www.stylusstudio.com for all your EDI reference needs!

As seen here, the C059 composite element contains four instances of the 3042 element, each of which is used to record part of an address. Notice that the first 3042 element is required (shown as M for "mandatory" in the table above).

Rendered as XML, a typical address compliant with the EDIFACT standard for NAD C059 composite elements might look like this:


   <NAD05>
	 <NAD0501>2 Beaufort Court</NAD0501>
	 <NAD0502>Apartment 3B</NAD0502>
	 <NAD0503>Anytown, MD</NAD0503>
	 <NAD0504>USA</NAD0504>
   </NAD05>

Based on the standard, the following address is also valid EDI because it contains the required first instance (shown as NAD0501):


   <NAD05>
	 <NAD0501>2 Beaufort Court</NAD0501>
   </NAD05>

However, General Anodyne Enterprises, Ltd. has decided to omit the first two fields from their address scheme, as they typically refer to locations using the facility and building names on their plants' campuses. An example follows:


   (empty)
   (empty)
   WEST ORCHARD FACILITY
   IMPLEMENTS AND DEVICES DIVISION

If this EDI fragment could be converted to XML, the address might be rendered as:


   <NAD05>
	 <NAD0501></NAD0501>
	 <NAD0502></NAD0502>
	 <NAD0503>WEST ORCHARD FACILITY</NAD0503>
	 <NAD0504>IMPLEMENTS AND DEVICES DIVISION</NAD0504>
   </NAD05>

Of course, this is not conformant with the EDIFACT standard for NAD C059 composite elements as it is missing the mandatory 3042 element, NAD0501.


Sample: anodyne_edi.edi

Following is a sample of the EDI file we want to convert to XML using the DataDirect XML Converter for EDI, with the NAD segment that represents the vairance from the EDIFACT standard highlighted:


UNB+UNOA:1+229899570:1+010094790:1+011206:0655+00000

000001352++DELJIT'
UNH+00000000000745+DELJIT:D:97A:UN'
BGM+241+00000000006814+9'
DTM+137:20011206:102'
DTM+206:2006:102'
NAD+ST+229899570::16++GENERAL ANODYNE ENTERPRISE, 
LTD.+::WEST ORCHARD FACILITY:IMPLEMENTS AND DEVICES 
DIVISION+BUCOLIA++02134'
NAD+SU+010094790::16++SYRINGE SYSTEMS 
BUSINESS+SYRINGE SYSTEMS 
PLANT:BUCOLIA:USA'
SEQ+3+1'
LIN+++4087894:IN::92'
IMD+++::92:INJECTOR'
GIR+1+SEQ NO= 50-019 ; RAN NO= 216632-533:AL'
PAC+16+++F:SMTOTE'
RFF+ON:75007015'
LOC+7+171'
QTY+131:16'

The DataDirect XML Converters™ Solution

DataDirect XML Converters™ provides a mechanism you can use to instruct the XML Converters engine about the differences in the EDI it is trying to convert to XML.

Step 1 — Build an XML Document

In our example, we want to let the XML Converters engine know that the first 3042 element is optional. We do this by constructing an XML document, using an XML editor like Stylus Studio 2007 XML Enterprise Suite, for example.


Stylus Studio is completely integrated with DataDirect XML Converters

In this document, which contains only the composite element we are interested in redefining (C059), we retain the four 3042 elements, but the mandatory attribute for the first of them has been set to "false", because we do not want it to be required.

To understand how to compose this XML, we used the CustomEDI-extend.xsd XML Schema provided with the DataDirect XML Converters™. Of course, we validated our XML against this XML Schema to be sure that it was valid.

Step 2 — Validate the XML Document Against a Custom EDI Message Type XML Schema

After you create the XML document that specifies how your custom EDI differs from the EDI standard, you need to validate it against one of the XML Schemas included with your Stylus Studio installation.


Stylus Studio is completely integrated with DataDirect XML Converters

This step ensures that the XML document is in a format that can be recognized and consumed by the DataDirect XML Converters™ engine.

Step 3 — Open the EDI File Using an XML Converter

Once we have a valid XML document describing General Anodyne Enterprises, Ltd.'s extension to the EDIFACT NAD segment standard, we're ready to go. First, we open the custom EDI file we want to convert as we would any file in Stylus Studio, but we select the Open Using XML Converter check box.

Stylus Studio is completely integrated with DataDirect XML Converters

Stylus Studio then displays the Select XML Converter dialog box, shown here:

Stylus Studio is completely integrated with DataDirect XML Converters

We use this dialog box to select the XML Converter for EDI and to specify the XML document that describes the changes to the EDI standard in the anodyne_edi.edi file.

Step 4 — Click OK to Convert anodyne_edi.edi to XML!

As you can see in the following illustration, our XML document contains only <NAD0503> and <NAD0504> elements, and not the <NAD0501> otherwise required by the EDIFACT standard for NAD C059 composite elements.

Use Stylus Studio for all your XML editing!

Using custom EDI message type tools with DataDirect XML Converters™ and Stylus Studio, you can easily manage proprietary EDI formats and convert them to XML.

More of a Bits and Bytes Kinda Person? Use the DataDirect XML Converters™ API

DataDirect XML Converters™ APIs for Java and .NET are bundled with your Stylus Studio 2007 XML Enterprise Suite installation, so if your requirements dictate that you use API for XML/EDI conversions, we've got you covered. And it's easy to use. These 9 lines of C# code perform the same custom EDI-to-XML conversion we just performed with Stylus Studio:

 1 using System;
 2 using DDTek.XmlConverter;
 3 public class ConverterOne {
 4     public static void Main(String[] args) {
 5         ConverterFactory factory = new ConverterFactory();
 6         ConvertToXml toXML = factory.CreateConvertToXml("converter:EDI:user=myCustomEDI.extension");
 7         toXML.Convert(new UriSource("anodyne_edi.edi"), new UriResult("anodyne_edi.edi.xml");
 8     }
 9 }

To learn more about the DataDirect XML Converters™ API, visit http://www.xmlconverters.com.


For More Information

Tired of reading? Watch a video that shows how easy it is to use DataDirect XML Converters™ in a .NET application.

PURCHASE STYLUS STUDIO ONLINE TODAY!!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Learn Stylus Studio in 6 Minutes

Can six minutes change your life? A new action-packed online video demonstration covers how to use Stylus Studio in just six minutes! Watch this video and change the way you develop XML applications forever!

Ask Someone You Know

Does your company use Stylus Studio? Do your competitors? Engineers from over 100,000 leading companies use Stylus Studio, and now you can ask someone from your own organization about their experiences using Stylus Studio.

 
Free Stylus Studio XML Training:
W3C Member