In this tutorial we’ll discuss how to validate Typed Documents as we’re creating them.

Typed Documents allows you to create EDI documents using high level objects and an easy to understand structure.  Please read this blog if you want to learn how to use Typed Documents to create EDI files.

After creating a Typed Document there are two ways to make sure the EDI data created is compliant with your implementation guide, for example an 5010 837 Professional.

The Long Way

 

Typed5010Document doc = new Typed5010Document();

//Create your document by adding loops and segment etc.

//Output EDI data to a string
string ediData =  doc837P.ToEDIString(new Delimiters());

//Write the data out to a file
File.WriteAllText("edi.text", ediData);

//Validate the EDI file
EDIValidator val = new EDIValidator();
val.EDIFile = "edi.text";
val.EDIRulesFile = "Rules_5010_837P_005010X222A1.Rules";

val.Validate();

var errors = val.Errors;
var warnings = val.Warnings;
var passed= val.Passed;

The above section clearly demonstrates how validate a Typed Document and with the EDIValidator component.  

There is a much easier way to accomplish this as well.

The Cleaner Way

 

Typed5010Document doc = new Typed5010Document();

//Create your document by adding loops and segment etc.

//Register for the OnValidationComplete event
doc.OnValidationComplete += new EventHandler(OnValidationComplete);

doc.Validate(new Delimiters(), "Rules_5010_837P_005010X222A1.Rules");

void doc_OnValidationComplete(object sender, TypedDocumentValidationEventsArgs e)
{
    var error = e.Errors;
    var warnings = e.Warnings;

    bool passed = e.Passed;

Now that was easy!

 

Take Charge Of EDI

RDPCrystal EDI Library

trial2