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:
<
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:
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
.
Stylus 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.
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 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 Stylus XML Convertersâ„¢. Of course, we
validated our XML against this XML Schema to be sure that it was valid.
Once we have a valid XML document describing General Anodyne Enterprises, Ltd.'s extension to the EDIFACT NAD segment standard, we can invoke the XML Converter for EDI. In addition to the EDI file we wish to convert to XML, we also specify the URL for our XML document. The XML Converter engine needs this document in order to understand how General Anodyne Enterprises, Ltd.'s NAD C059 composite element differs from that defined in the EDI standard. All other aspects of the EDIFACT standard remain intact and are enforced by the XML Converters engine.
So, to convert anodyne_edi.edi to XML, we invoke the XML Converter for EDI like this in Java:
import javax.xml.transform.stream.*;
import com.ddtek.xmlconverter.*;
public
class
ConverterOne {
public
static
void
main(String[] args) throws Throwable {
ConverterFactory factory =
new
ConverterFactory();
ConvertToXML toXML =
factory.newConvertToXML(
"converter:EDI:user=myCustomEDI.extension"
);
toXML.convert(
new
StreamSource(
"anodyne_edi.edi"
),
new
StreamResult(
"anodyne_edi.edi.xml"
);
}
}
And like this in C#:
<font>1 </font><font>
using
</font> System;
<font>2 </font><font>
using
</font> DDTek.XmlConverter;
<font>3 </font><font>
public
class
</font> <font>ConverterOne</font> {
<font>4 </font> <font>
public
static
void
</font> Main(<font>String</font>[] args) {
<font>5 </font> <font>ConverterFactory</font> factory <font>=</font> <font>
new
</font> <font>ConverterFactory</font>();
<font>6 </font> <font>ConvertToXml</font> toXML <font>=</font>
factory<font>.</font>CreateConvertToXml(<font>
"converter:EDI:user=myCustomEDI.extension"
</font>);
<font>7 </font> toXML<font>.</font>Convert(<font>
new
</font> <font>UriSource</font>(<font>
"anodyne_edi.edi"
</font>),
<font>
new
</font> <font>UriResult</font>(<font>
"anodyne_edi.edi.xml"
</font>);
<font>8 </font> }
<font>9 </font>}
In both examples, the user
property is used to specify the URL of our XML document.
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 variance 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'
As you can see in the following illustration that shows the converted EDI file, 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 Stylus XML Convertersâ„¢ custom EDI message type tools, you can easily manage proprietary EDI formats and convert them to XML.
Tired of reading? Watch a video that shows how easy it is to use Stylus XML Convertersâ„¢ in a .NET application.