Validating X12 Documents with XML schemas

In order to make sure the X12 content we're dealing with is valid, either before transforming it or after, we need something against which to validate it.

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

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

We can save the XML Schema so that we do not need to rebuild it each time. And by assigning that schema to a folder in our project window, any X12 Document URL placed into that folder will get validated with the assigned schema.


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

Open the X12 document as XML

Use File|Open and select your X12 document. You may use x12-sample.txt for this demonstration.

But... before pressing the Open button, put a check in the box Convert to XML using converter.

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

Your X12 file will now be opened in the XML editor, as fully-commented XML.


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

Create the corresponding XML schema

Now you need to generate the appropriate schema. If you're not sure which transaction set or which release the X12 files is from, just look in the editor. There will be a line that starts like this:

<GS08><!--480: Version / Release / Industry-->003040
    
<!--Draft Standards Approved for Publication by ASC X12
    Procedures Review Board through October 1993
--></GS08>

and that's your release - in this case, 003040. Next find the line that starts like this:

<ST01><!--143: Transaction Set Identifier Code-->831
    
<!--X12.49 Application Control Totals--></ST01>

and that's your transaction set.

Do File|Document Wizards...|X12 to XML Schema and choose release 003040 and transaction set 831, and you'll have a new document created that is the schema for this X12 document.

Use File|Save As... and save it as something like 3040-831.xsd. You now have a reusable XML Schema file for validating X12 Application Control Total transaction sets for release 003040.


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

Attach the schema to the document

Now, let's tell the document where to find the schema. Use XML|Associate XML With Schema... and choose the file you just created. 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 X12 document can now be validated against the XML Schema you've created.

This can be used to make sure the X12 EDI data you are getting in matches what you expect. It can also be used at the end of an XQuery or XSLT transform to make sure your output has valid content, immediately before writing back through the EDI converter to turn it into valid X12. The XML Converters are specifically design to help you do this, as is the data conversion API.


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 X15?

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.

 
Free Stylus Studio XML Training:
W3C Member