Validating EDIFACT Documents with XML Schemas

Either before or after transforming EDIFACT content, we should make sure that we have all of the necessary components, our codes are in our codelists, and everything is in the right places.

Stylus Studio® includes a dictionary containing the EDIFACT standards across multiple versions. From this, the following steps will let us validate an EDIFACT document.

  1. Open the EDIFACT document as XML
  2. Create the corresponding XML schema
  3. Attach the schema to the document
  4. Validate

Once we've gone through these four steps, subsequent validations of the same document structure will be even shorter. If we use our project window and assign that schema to a folder therein, any EDIFACT Document URL placed into that project folder will get validated with the given schema.


Open the EDIFACT document as XML

Use File|Open and select your EDIFACT document. This demonstration uses the sample file edifact-sample.txt available on this server.

Before pressing the Open button, check the the box labeled Convert to XML using adapter.

Another dialog asking for which adapter will come up. Choose the "Electronic Data Interchange (EDI)" adapter and press OK.

Your EDIFACT document will now be opened in the XML editor, as fully-commented XML.

Open the EDIFACT document as XML (Click to enlarge)
(click to enlarge)

Create the corresponding XML schema (Click to enlarge)
(click to enlarge)

Create the corresponding XML schema

Now you need to generate a matching schema. If you're not sure which message type or which version the EDIFACT files is from, just look in the editor. There will be a line that starts like this:

<UNH0201><!--0065: Message type-->ORDERS</UNH0201>

and that's your message type — in this sample ORDERS. Almost immediately below it will be a line like this:

<UNH0203><!--0054: Message release number-->03B</UNH0203>

which contains your version number.

Use File|Document Wizards...|EDIFACT to XML Schema and choose version 03B of message ORDERS and a new tab will open with the newly-generated XML Schema that cooresponds to the content of the EDIFACT file you just converted.

Do File|Save As... and save it as 03B-ORDERS.xsd. You now have a reusable XML Schema file for validating EDIFACT version D03B Purchace Order Messages.


Attach the schema to the document (Click to enlarge)
(click to enlarge)

Attach the schema to the document

Next we need to associate this schema with our document. Go to the menubar and choose XML|Associate XML With Schema... and then open the XSD file you just saved. In a few seconds, the tags should change color to indicate that a schema was found and that they are a valid part of the schema.


Validate

Press the button and your EDIFACT file can now be validated against the XML Schema you just created.

This can be used to make sure the EDIFACT input you are receiving matches what you expect. It can also be used at the result end of an XQuery or XSLT transform to make sure your output has valid content — which is especially useful to do before writing through the EDI adapter to turn it into valid EDIFACT.


It's phenomenal to consider what we've just done. We've used two completely different technologies — EDIFACT and XML Schema (with completely unrelated ancestries) — and we've used them together in a new way to solve the tough problem of validating EDI. You can use these same features in your projects as well: see details about using the embedded XML converters directly and in conjunction with XSLT and XQuery.

PURCHASE STYLUS STUDIO ONLINE TODAY!!

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

Buy Stylus Studio Now

Try Stylus EDI Tools

Simplify working with Electronic Data Interchange (EDI) with Stylus Studio®'s award-winning EDI Tools — Download a free trial of our today!

What's New for Stylus Studio® X16?

New XQuery & Web Services Tools, Support for MySQL, PostgreSQL, HL7 EDI, Microsoft .NET Code Generation and much more!

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.

Stylus Studio® EDIFACT Zone

Simplify your next legacy data integration project with the help of the EDIFACT Zone, the world's largest, free online reference covering all EDIFACT and UN/CEFACT versions.

 
Free Stylus Studio XML Training:
W3C Member