How To Parse, Load And Validate using .Net

In this tutorial we’ll discuss how to parse, load and validate EDI data using C#.Net.  Any .Net compatible language can be used, for example VB.Net.   EDIValidator is arguably one of the most important components in RDPCrystal EDI Library.  It takes two parameters, a validation rules file and an EDI file ( or string ) to validate.   The overall validation process looks like the following:

A validation rule file contains all the data elements, segments, and loop meta data pertaining to a specific implementation guide.

The Code

// Create an instance of the EDIValidator object
EDIValidator validator = new EDIValidator();
 
// Set the source of EDI data, whether you are validating from an in-memory string or a file

validator.EDISource = EDISource.File; // Or EDISource.DataString

// Set the validation rules
validator.EDIRulesFile = “C:\\Rules_5010_834_005010X220A1.Rules”;

// Set the EDI file to load and validate
validator.EDIFile = “C:\\EDIFile.edi”;

// Validate
validator.Validate();

// Check if the EDI file passed
if (validator.Passed)
{
   Console.WriteLine(“Passed”);

   //Get the EDI file just parsed
   EDILightWeightDocument file = validator.EDILightWeightDocument;
}
else
{
  
// Display all errors
   foreach (EDIError error in ediValidator.Errors)
   {
      Console.WriteLine(error.LineNumber.ToString() + ” ” + error.Loop + ” ” + error.Segment + ” ” + error.Message.ToString());
   }

}

Now that was easy!

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2