%@ Page Language="C#" Inherits="Page" MasterPageFile="~/templates/Master1.master"
Title="Example: Converting Custom EDI Message Types to XML"
KeyWords="EDI XML Converters, XML EDI Converters, EDI XML Conversions, XML EDI Conversions, custom EDI message types"
%>
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 <%=ConfigurationManager.AppSettings["DDXC"]%>. 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. 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: Based on the standard, the following address is also valid EDI because it contains the required first instance (shown as 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: If this EDI fragment could be converted to XML, the address might be rendered as: Of course, this is not conformant with the EDIFACT standard for NAD C059 composite elements as it is missing the mandatory 3042 element, 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: <%=ConfigurationManager.AppSettings["DDXC"]%> 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.Example: Converting a Custom EDI Message Type with <%=ConfigurationManager.AppSettings["DDXC"]%>
The Problem

<NAD05>
<NAD0501>2 Beaufort Court</NAD0501>
<NAD0502>Apartment 3B</NAD0502>
<NAD0503>Anytown, MD</NAD0503>
<NAD0504>USA</NAD0504>
</NAD05>
NAD0501):
<NAD05>
<NAD0501>2 Beaufort Court</NAD0501>
</NAD05>
(empty)
(empty)
WEST ORCHARD FACILITY
IMPLEMENTS AND DEVICES DIVISION
<NAD05>
<NAD0501></NAD0501>
<NAD0502></NAD0502>
<NAD0503>WEST ORCHARD FACILITY</NAD0503>
<NAD0504>IMPLEMENTS AND DEVICES DIVISION</NAD0504>
</NAD05>
NAD0501.
Sample: anodyne_edi.edi
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 <%=ConfigurationManager.AppSettings["DDXC"]%> Solution
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.

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 <%=ConfigurationManager.AppSettings["DDXC"]%>. Of course, we validated our XML against this XML Schema to be sure that it was valid.
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.

This step ensures that the XML document is in a format that can be recognized and consumed by the <%=ConfigurationManager.AppSettings["DDXC"]%> engine.
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 then displays the Select XML Converter dialog box, shown here:

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.
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.

Using custom EDI message type tools with <%=ConfigurationManager.AppSettings["DDXC"]%> and Stylus Studio, you can easily manage proprietary EDI formats and convert them to XML.
<%=ConfigurationManager.AppSettings["DDXC"]%> 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 <%=ConfigurationManager.AppSettings["DDXC"]%> API, visit http://www.xmlconverters.com.
Tired of reading? Watch a video that shows how easy it is to use <%=ConfigurationManager.AppSettings["DDXC"]%> in a .NET application.