Batch Parsing of 835's

Feb 18, 2013 at 9:32 PM
Edited Feb 18, 2013 at 11:37 PM
I have read the other discussion that was held on this topic and have tried to incorporate the suggestions into my project but cannot seem to get it to work. I have no experience with C# so that doesn't help. How do I incorporate the transform XML to CSV stream code into a batch process? The main issue I am running into is I get an error saying "Index was outside the bounds of the array." It is also unable to validate parser.ParseMultiple. Thanks ahead of time.

This is my Program.cs file.

using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System;
using System.Xml;
using System.Xml.Xsl;
using OopFactory.X12.Parsing;
using OopFactory.X12.Parsing.Model;

namespace OopFactory.Edi835Parser
{
class Program
{
    static void Main(string[] args)
    {
       string inputPath = args[0];

       foreach (string inputFilename in Directory.GetFiles(@"C:\SCANNING\NEWFOLDER\", "*.rmt"))
        {
            Stream transformStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.Edi835Parser.Transformations.X12-835-LineItems-XML-to-CSV.xslt");
            Stream inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read);

            X12Parser parser = new X12Parser();
            int index = 1;
            foreach (Interchange interchange in  parser.ParseMultiple(inputStream))
            {
                string xml = interchange.Serialize();

                var transform = new XslCompiledTransform();
                transform.Load(XmlReader.Create(transformStream));

                string outputFilename = index == 1 ? string.Format("{0}.csv", inputFilename) : string.Format("{0}_{1}.csv", inputFilename, index++);
                Stream outputFile = new FileStream(outputFilename, FileMode.Create, FileAccess.Write);
                transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), outputFile);
            }
        }
    }

    public static string inputPath { get; set; }
}
}
Coordinator
Mar 29, 2013 at 1:34 AM
Were you able to get this to work?

BTW, when you work with Xslt files. I would first make sure the xslt can work in the Visual Studio IDE, by using the XML menu when you are in your xslt file to do test transforms. The properties window for the xslt (when your cursor is in the text editor of the xslt file) should allow to specify input and output files.

If you know the problem is not with your xslt than I would also check that you have set the BuildAction to Embedded Resource on the xslt properties (when selecting the file in solution explorer).

It is not apparent to me from the code where you index out of bound error is happening. The only array I see is your args[0]. This might be the error if in your debug you have not set any command line arguments.

Let me know if any of that helps.