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.
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.
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.
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.
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.
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!
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!
Learn XQuery in 10 Minutes!
Say goodbye to 10-minute abs, and say Hello to "Learn XQuery in Ten Minutes!", the world's fastest and easiest XQuery primer, now available for free!