EDI.Net icon indicating copy to clipboard operation
EDI.Net copied to clipboard

How do you parse a subelement?

Open NickMcG opened this issue 3 years ago • 1 comments

I have some EDI that I'd like to parse that looks like this:

REF*WS*CHBOH*0*QO>358>AD>20220608~

In other words, 358, AD, and 20220608 are all subelements of the REF04 element. Is there a way for me to get at the data?

I currently have REF defined as this:

        [EdiSegment, EdiPath("REF")]
        public class REF
        {
            [EdiValue(Path = "REF/0")]
            public string ReferenceIdentificationQualifier { get; set; }

            [EdiValue(Path = "REF/1")]
            public string ReferenceIdentification { get; set; }

            [EdiValue(Path = "REF/2")]
            public string Description { get; set; }

            [EdiValue(Path = "REF/3")]
            public string RefIdentifier { get; set; }
        }

When I parse and print out the data, I can see REF*WS*CHBOH*0*QO, but I can't get to the >358>AD>20220608.

Is there a way to get it to either drop the subelements into a property, or just eagerly grab everything? I'm perfectly fine parsing it after the majority of the EDI has been handled.

NickMcG avatar Feb 08 '22 23:02 NickMcG

Hi @NickMcG,

you could make use of an additional structural class for elements and make use of the attribute [EdiElement]. Elements contain subelements (components) that are the values so in your example above REF/4 should be mapped to a class that has 4 components as properties.

check this model here that contains an example of Element and Segment use in the same file (The example transmission file).

cleftheris avatar Feb 21 '22 10:02 cleftheris