Validating Typed Documents

Index

    Validating Typed Documents

    Typed Documents allows you to create EDI data 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 a few ways to make sure the EDI data created is compliant with your implementation guide, for example an 5010 837 Professional.

    Example – Using EDIValidator

    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 or a string.  The code below writes it to the 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;

    Example – Using an Event

    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;
      var passed = e.Passed;

    Example – Using The GetValidator Method

    Typed5010Document doc = new Typed5010Document();

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

    …..

    EDIValidator validator = doc.GetValidator(new Delimiters(), “Rules_5010_837P_005010X222A1.Rules”);

    validator .Validate();

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

    in Typed Documents
    Did this article answer your question?