EDI Validator – Converting To XML

Index

    Converting To XML

    In order to convert EDI data to XML the data first needs to be loaded into memory.  Using the EDIValidator the XML data will have the same parent/child hierarchy exhibited in the EDI file loop/segment structure.

    Example

    // Create an instance of the EDIValidator object
    EDIValidator validator = new EDIValidator();

    // Set the type of EDI file that you are about the validate
    validator.EDIFileType = FileType.X12;

    // 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 EDI rules file.  The entire EDI Rules can also be passed in using the ‘EDIRuleFileData’ property.  There is a different rules file per implementation guide
    validator.EDIRulesFile = “C:\\EDIFile.Rules“;

    // Set the EDI file to load
    validator.EDIFile = “C:\\EDIFile.txt“;
    // Validate and Load
    validator.Validate();
    if (validator.EDILightWeightDocument != null)
    {
       //Get the EDI file just parsed
       EDILightWeightDocument file = validator.EDILightWeightDocument;
       //Convert to XML
       XmlDocument xmlDoc = file.ToXml();
       //Or save to a file
       file.ToXml(“C:\\EDIFile.xml);
    }

    If you need to convert EDI data to XML in a flat structure (without the parent/child hierarchy) use the EDIFileLoader component

    in
    Did this article answer your question?

    Related Articles