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
EDIValidator validator = new EDIValidator();
// 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());
}
}