This project has moved and is read-only. For the latest updates, please go here.

Help using the library

Dec 9, 2013 at 6:01 PM
Hi,

I'm really lost at how to use this library.
Based on the samples from the Test Project, I was able to parse a D98A_INSDES Message to Interchange like this:
    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        TextBox2.Text = OpenFileDialog1.FileName
        Dim filename As String = TextBox2.Text

        Dim parser As IEdiParser = New EdiParser()
        Dim streamOne As Stream = New FileStream(filename, FileMode.Open)
        Dim interchange As INTERCHANGE = parser.ToInterchange(Of INTERCHANGE)(streamOne, Nothing)
        Dim xml As XElement = parser.Serialize(interchange)

        Dim xsd As String = "c:\users\primeiro.ultimo\documents\visual studio 2013\Projects\EDITest\EDITest\Schema\EF_EFCT_D98A_INSDES.xsd"
        Dim schemas As XmlSchemaSet = New XmlSchemaSet()
        Dim stream As Stream = New FileStream(xsd, FileMode.Open)
        Dim schema As XmlSchema = Nothing
        If stream IsNot Nothing Then
            schema = XmlSchema.Read(stream, Nothing)
            schemas.Add(schema)
        End If

        Dim doc As XDocument = New XDocument()

    End Sub
I then write the output of doc to a textBox, which presents itself as a XML File. No problems this far.
But now I want to start retrieving values from this XML output (based on the doc).
For example, how do I get the value of the tag D_1004_1?

I've tried numerous ways but always end up with a value of Nothing or an error is thrown.

I need to read the EDI file and start retrieving values to insert into the Database..

Can anyone help please? It's been 3 days with little to no success.
Dec 10, 2013 at 11:08 AM
Edited Dec 10, 2013 at 12:34 PM
Based on a few more experiences with the library, I came up with the following code:
Dim parser As IEdiParser = New EdiParser()
        Dim streamOne As Stream = New FileStream(filename, FileMode.Open)
        Dim interchange As INTERCHANGE = parser.ToInterchange(Of INTERCHANGE)(streamOne, Nothing)
        Dim xml As XElement = parser.Serialize(interchange)

        Dim xsd As String = "c:\users\primeiro.ultimo\documents\visual studio 2013\Projects\EDITest\EDITest\Schema\EF_EFCT_D98A_INSDES.xsd"
        Dim schemas As XmlSchemaSet = New XmlSchemaSet()
        Dim stream As Stream = New FileStream(xsd, FileMode.Open)
        Dim schema As XmlSchema = Nothing
        If stream IsNot Nothing Then
            schema = XmlSchema.Read(stream, Nothing)
            schemas.Add(schema)
        End If

        Dim doc As XDocument = New XDocument(xml)
        Dim vals As String() = New String() {}
        Dim param As XName = "GROUPS"
        Dim childList As IEnumerable(Of XElement) = _
            From el In doc.Root.Elements() _
            Select el
        For Each node As XElement In childList
            ReDim Preserve vals(vals.Length)
            vals(vals.Length - 1) = node.ToString
            TextBox1.AppendText(node.ToString & Environment.NewLine)
        Next
This is the original message:
UNA:+.? '
UNB+UNOC:3+codigo emissor:14+codigo receptor:14+data:hora+IDMensagem'
UNH+IDMensagem2+INSDES:D:98A:UN'
BGM+80E+numero do documento+9'
DTM+137:data documento:102'
DTM+2:data e hora de entrega desejada:203'
FTX+DEL+++OBS1:Observações de entrega'
FTX+DEL+++OBS2:Observações de entrega'
FTX+DEL+++OBS3:Observações de entrega'
FTX+DEL+++OBS4:Observações de entrega'
RFF+VN:referencia interna picking'
RFF+ON:pedido do cliente'
NAD+BY+codigo interno::91++nome comprador'
NAD+SU+5600000768143::9++Mangreen'
NAD+DP+codigo interno recebedor::91++local entrega+rua entrega+localidade entrega++codigo postal entrega'
NAD+LSP+codigo operador logistico::91++nome operador logistico'
LIN+1++codigo ean artigo:EN'
PIA+1+codigo itf caixa:BP+codigo interno:SA'
IMD+F++:::descricao'
QTY+113:quantidade de unidade de picking:unidade picking'
UNT+total segmentos+IDMensagem2'
UNZ+1+IDMensagem'
Parsing the message produces the following output:
<INTERCHANGE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.edifabric.com/edifact">
  <S_UNB>
    <C_S001>
      <D_0001_1>UNOC</D_0001_1>
      <D_0002_2>3</D_0002_2>
    </C_S001>
    <C_S002>
      <D_0004_1>codigo emissor</D_0004_1>
      <D_0007_2>14</D_0007_2>
    </C_S002>
    <C_S003>
      <D_0010_1>codigo receptor</D_0010_1>
      <D_0007_2>14</D_0007_2>
    </C_S003>
    <C_S004>
      <D_0017_1>data</D_0017_1>
      <D_0019_2>hora</D_0019_2>
    </C_S004>
    <D_0020_5>IDMensagem</D_0020_5>
  </S_UNB>
  <GROUPS>
    <GROUP>
      <MESSAGES>
        <MESSAGE>
          <M_INSDES>
            <S_UNH>
              <D_0062_1>IDMensagem2</D_0062_1>
              <C_S009>
                <D_0065_1>INSDES</D_0065_1>
                <D_0052_2>D</D_0052_2>
                <D_0054_3>98A</D_0054_3>
                <D_0051_4>UN</D_0051_4>
              </C_S009>
            </S_UNH>
            <S_BGM>
              <C_C002>
                <D_1001_1>80E</D_1001_1>
              </C_C002>
              <C_C106>
                <D_1004_1>numero do documento</D_1004_1>
              </C_C106>
              <D_1225_3>9</D_1225_3>
            </S_BGM>
            <S_DTM>
              <C_C507>
                <D_2005_1>137</D_2005_1>
                <D_2380_2>data documento</D_2380_2>
                <D_2379_3>102</D_2379_3>
              </C_C507>
            </S_DTM>
            <S_DTM>
              <C_C507>
                <D_2005_1>2</D_2005_1>
                <D_2380_2>data e hora de entrega desejada</D_2380_2>
                <D_2379_3>203</D_2379_3>
              </C_C507>
            </S_DTM>
            <S_FTX>
              <D_4451_1>DEL</D_4451_1>
              <C_C108>
                <D_4440_1>OBS1</D_4440_1>
                <D_4440_2>Observa��es de entrega</D_4440_2>
              </C_C108>
            </S_FTX>
            <S_FTX>
              <D_4451_1>DEL</D_4451_1>
              <C_C108>
                <D_4440_1>OBS2</D_4440_1>
                <D_4440_2>Observa��es de entrega</D_4440_2>
              </C_C108>
            </S_FTX>
            <S_FTX>
              <D_4451_1>DEL</D_4451_1>
              <C_C108>
                <D_4440_1>OBS3</D_4440_1>
                <D_4440_2>Observa��es de entrega</D_4440_2>
              </C_C108>
            </S_FTX>
            <S_FTX>
              <D_4451_1>DEL</D_4451_1>
              <C_C108>
                <D_4440_1>OBS4</D_4440_1>
                <D_4440_2>Observa��es de entrega</D_4440_2>
              </C_C108>
            </S_FTX>
            <G_RFF>
              <S_RFF>
                <C_C506>
                  <D_1153_1>VN</D_1153_1>
                  <D_1154_2>referencia interna picking</D_1154_2>
                </C_C506>
              </S_RFF>
            </G_RFF>
            <G_RFF>
              <S_RFF>
                <C_C506>
                  <D_1153_1>ON</D_1153_1>
                  <D_1154_2>pedido do cliente</D_1154_2>
                </C_C506>
              </S_RFF>
            </G_RFF>
            <G_NAD>
              <S_NAD>
                <D_3035_1>BY</D_3035_1>
                <C_C082>
                  <D_3039_1>codigo interno</D_3039_1>
                  <D_3055_3>91</D_3055_3>
                </C_C082>
                <C_C080>
                  <D_3036_1>nome comprador</D_3036_1>
                </C_C080>
              </S_NAD>
            </G_NAD>
            <G_NAD>
              <S_NAD>
                <D_3035_1>SU</D_3035_1>
                <C_C082>
                  <D_3039_1>5600000768143</D_3039_1>
                  <D_3055_3>9</D_3055_3>
                </C_C082>
                <C_C080>
                  <D_3036_1>Mangreen</D_3036_1>
                </C_C080>
              </S_NAD>
            </G_NAD>
            <G_NAD>
              <S_NAD>
                <D_3035_1>DP</D_3035_1>
                <C_C082>
                  <D_3039_1>codigo interno recebedor</D_3039_1>
                  <D_3055_3>91</D_3055_3>
                </C_C082>
                <C_C080>
                  <D_3036_1>local entrega</D_3036_1>
                </C_C080>
                <C_C059>
                  <D_3042_1>rua entrega</D_3042_1>
                </C_C059>
                <D_3164_6>localidade entrega</D_3164_6>
                <D_3251_8>codigo postal entrega</D_3251_8>
              </S_NAD>
            </G_NAD>
            <G_NAD>
              <S_NAD>
                <D_3035_1>LSP</D_3035_1>
                <C_C082>
                  <D_3039_1>codigo operador logistico</D_3039_1>
                  <D_3055_3>91</D_3055_3>
                </C_C082>
                <C_C080>
                  <D_3036_1>nome operador logistico</D_3036_1>
                </C_C080>
              </S_NAD>
            </G_NAD>
            <G_LIN>
              <S_LIN>
                <D_1082_1>1</D_1082_1>
                <C_C212>
                  <D_7140_1>codigo ean artigo</D_7140_1>
                  <D_7143_2>EN</D_7143_2>
                </C_C212>
              </S_LIN>
              <S_PIA>
                <D_4347_1>1</D_4347_1>
                <C_C212_2>
                  <D_7140_1>codigo itf caixa</D_7140_1>
                  <D_7143_2>BP</D_7143_2>
                </C_C212_2>
                <C_C212_3>
                  <D_7140_1>codigo interno</D_7140_1>
                  <D_7143_2>SA</D_7143_2>
                </C_C212_3>
              </S_PIA>
              <S_IMD>
                <D_7077_1>F</D_7077_1>
                <C_C273>
                  <D_7008_4>descricao</D_7008_4>
                </C_C273>
              </S_IMD>
              <S_QTY>
                <C_C186>
                  <D_6063_1>113</D_6063_1>
                  <D_6060_2>quantidade de unidade de picking</D_6060_2>
                  <D_6411_3>unidade picking</D_6411_3>
                </C_C186>
              </S_QTY>
            </G_LIN>
            <S_UNT>
              <D_0074_1>total segmentos</D_0074_1>
              <D_0062_2>IDMensagem2</D_0062_2>
            </S_UNT>
          </M_INSDES>
        </MESSAGE>
      </MESSAGES>
    </GROUP>
  </GROUPS>
  <S_UNZ>
    <D_0036_1>1</D_0036_1>
    <D_0020_2>IDMensagem</D_0020_2>
  </S_UNZ>
</INTERCHANGE>
What I did notice, by writing the "output" to a string array is that the final array contains one 3 elements: UNB, GROUPS and UNZ.
Am I doing anything wrong or shouldn't the output be an array with each tag?

The main contents I am looking for are in the GROUPS section. As an example, based on the code provided, how would I get the value in the UNH tag?
I've never worked with EDI and only a tiny bit with xml, so any help is welcome.

As an additional note, I'm trying to parse INSDES messages..

Best Regards,
Celso Santos
Dec 10, 2013 at 5:41 PM
Also,

I've just noticed that when I import the Framework DLL into the project I'm using (which is in VB.NET), the Helpers namespace isn't available.

Shouldn't the Edifabric be marked as CLS compliant?
Dec 11, 2013 at 12:05 PM
Have a look at the xml - groups->group->messages->message->insdes->unh

Refer to previous discussions on how to serialize the message, which is XElement.
Dec 11, 2013 at 12:10 PM
What do you mean by 'the Helpers namespace isn't available.' ?

All you need is IEdiParser. All helper code is internal, exactly for situations like yours, to restrict you from doing things the way they shouldn't be done.

Cheers,
Kamen