EDIdEv - Electronic Data Interchange Development

Converting an EDI file to XML

This is a source code in VB .NET that converts an EDI file to an XML file using the built-in functions of the EDIdEv Framework EDI (FREDI) component.  The basic algorithm is:

  1. Instantiate an EDI document object (of the FREDI component)

  2. Load the appropriate SEF file, which is essentially a schema of a Transaction Set so that FREDI would know how to parse the corresponding EDI file correctly.

  3. Load the EDI file into the EDI document object.

  4. Save the EDI document object as an XML output.

        Private Sub cmdConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConvert.Click
            'Recommended only for short EDI files

            Dim oEdiDoc As ediDocument
            Dim spath As String

            cmdConvert.Enabled = False
            Me.Cursor = Cursors.WaitCursor

            spath = AppDomain.CurrentDomain.BaseDirectory

            oEdiDoc.Set(oEdiDoc, New ediDocument)   'instantiate EDI document 'oEdiDoc = New ediDocument

            'Load Schema for transaction set 850 4010
            oEdiDoc.LoadSchema(spath & "850_X12-4010.SEF", SchemaTypeIDConstants.Schema_Standard_Exchange_Format)

            'Load 850 4010 EDI File
            oEdiDoc.LoadEdi(spath & "850.X12")

            'Save to XML format
            oEdiDoc.Save(spath & "850_X12_XmlOutput.XML", OutputTypeIDConstants.OutputType_XML)

            'Display XML string on screen

            Me.Cursor = Cursors.Default
            MsgBox("Done. XML file =  " & sXmlFile)

            oEdiDoc.Dispose()   'oEdiDoc = Nothing

        End Sub


Below is a partial image of the XML file output


The actual program can be downloaded from here

    Click here to download a trial version of the Framework EDI