shogg / edifact

Read edifact into your Go data structures.
MIT License
18 stars 7 forks source link

How to deal with with repeat segments? #11

Closed wiegell closed 9 months ago

wiegell commented 9 months ago

Hello there @shogg, thanks for making this package. I have tried it for a project at work, but we have repeat segment statements, and i don't see a way to extract them with this package?

There is actually also one in the ORDERS spec:

image

I don't see a clear syntax as to how to extract both lines, i tried:

image

But that gives:

image

And in our project i also tried making a "fake" segment group (not in my standardised spec), with only the one FTX tag, to try and parse the repeat segments to an array (which is what i really want), but couldn't get it to work either. To complicate it further, our spec actually has a single mandatory FTX+ACM followed by 20 conditional FTX+SPC, so the base tag is the same! (i would be glad with just one single array including both FTX+ACM and FTX+SPC) Here is an example:

FTX+ACM+P00++Væsentlige fejlstillinger;højre fod'
FTX+SPC+P00++Mobil pes planus transversus?:Ja'
FTX+SPC+P00++Hallux valgus?:Ja'

We consume a variant of this spec: https://service.unece.org/trade/untdid/d09a/trmd/medrpt_c.htm

Hope to hear from you, kind regards

shogg commented 9 months ago

I have a simple patch for Comments []string. Comment1, Comment2 will still not work. Tomorrow I'll test corner cases before pushing.

wiegell commented 9 months ago

Wow that would be amazing! thank you! Comments []string is the ideal case

shogg commented 9 months ago

I pushed the patch.

There is a new test in unmarshal_rffs_test.go to show what to expect when unmarshalling into a slice.

wiegell commented 9 months ago

it works perfectly, thanks alot!