TransformToX12 How To... first attempt

Jul 1, 2011 at 9:43 PM
Edited Jul 1, 2011 at 9:44 PM

Baby steps... :)

Here's my first attempt at implementing the "TransformToX12" function in an app. If there's a better way to implement the functionality, please let me know.  Yes it does work!  (However, I couldn't figure out how to get the whitespace option to work...)


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using OopFactory.X12.Parsing;
using OopFactory.X12.Parsing.Model;

namespace OopFactory.X12.TransformToX12
    class Program
        static void Main(string[] args)
            string x12Filename = args[0];
            string outputFilename = args.Length > 1 ? args[1] : x12Filename + ".edi";

            StreamReader fs = new StreamReader(x12Filename);
            string xmltext = fs.ReadToEnd();
            OopFactory.X12.Parsing.X12Parser parser = new Parsing.X12Parser();
            string x12 = parser.TransformToX12(xmltext);
            //**Alternate method that I can't get to work**
            //FileStream fs = new FileStream(x12Filename, FileMode.Open);
            //OopFactory.X12.TransformToX12.Program transformer = new TransformToX12.Program();
            //string x12 = transformer.ToString(fs);

            FileStream outputFs = new FileStream(outputFilename, FileMode.Create);
            StreamWriter writer = new StreamWriter(outputFs);

Jul 5, 2011 at 7:52 PM

You are using code I have not yet released! Kudos to you.

Are you trying to remove white space or add white space?  To the XML or X12?

BTW, thanks for all of your other feedback last week.  I plan to fix the Unbundle stuff this week and add you sample EDI's.  I hope to get a version released this weekend with these changes.

Let me know if you would like to contribute in any other way.  You can be added as an "Editor" if you want to add discussion pages.  I would also like to give you credit as a contributor from the documentation page for the transaction sets that you are helping to improve.  I do have a selfish motive in that I want to encourage others to contribute by showing active contributors.  Let me know what you think.

Jul 5, 2011 at 8:44 PM

Yes, I was trying to configure it so I could turn on & off the white space option, but couldn't figure that out.

Your welcome for the feedback!  I do appreciate your responsiveness.

Yes, I'd be honored to contribute in any way I can. I'm probably a bit stronger on the admin side of things (vs. programming) so anything I can help out with in terms of documentation, discussion pages, etc. I'll be happy to help.

Jul 10, 2011 at 8:07 PM

I finally had a change to look at this.  All the output that I have looked at does not have white space (except the one's needed in the fixed width ISA segment).  I think I am missing something.  IS it the X12 that you are still seeing white space?

BTW, the method is now in released code.  I just put out release 2.1.7.

Jul 12, 2011 at 4:47 PM

I'm not sure how to use the method you added in 2.1.7... but the code above still works.  (I just added an issue suggesting an additional application "TransformToX12.exe" be included in future releases.)

To clarify on the whitespace.  I was attempted to figure out how to add whitespace to the resulting X12 file in the TransformToX12 process.  

Jul 13, 2011 at 12:39 AM

The easiest way to get the white space back in is to use the parser to load it back into the Interchange object, then you can call the interchange.SerializeToX12(true);

I'll add that option to the new TransformToX12 exe that I will add to the next release.  The whitespace won't be valid for transmission, but it will be useful for internal storage and troubleshooting.