Parse EDI text into segments and elements¶
EdiSegmentParser.Parse and its cascaded EdiDataElementParser/EdiCompositeDataElementParser collaborators split raw EDI text on the ~, *, and : delimiters respectively, building the flat segment/element list consumed by Build the X12 envelope hierarchy.
| Field | Value |
|---|---|
| Operation ID | OP-06 |
| Trigger | Called by Read an EDI interchange file, or directly by a consumer. |
| Inputs | Raw EDI string. |
| Outputs | List<IEdiSegment>. |
| Primary components | EdiSegmentParser.Parse, EdiDataElementParser.Parse, EdiCompositeDataElementParser.Parse |
| Entry point | Common\SAIF.Common.Files\Edi\Core\Parsers\EdiSegmentParser.cs, EdiDataElementParser.cs, EdiCompositeDataElementParser.cs |
Steps¶
- Split the input on
~(EdiRecordBase.SegmentDelimiter) withRemoveEmptyEntries(BR-018). - For each segment token, create an
EdiSegmentwithIndex = IndexingSequence.NextValue(delegated:SAIF.Framework.Common→Sequence),Value = token, andDataElements = new EdiDataElementParser().Parse(token). EdiDataElementParser.Parsesplits on*.- A token containing
:becomes anEdiCompositeDataElementwhose children come fromEdiCompositeDataElementParser.Parse(split on:) (BR-019). - The first token receives index 0 and all others receive sequence values (BR-020).
ediSegment.SegmentId = ediSegment.GetChildValue(0)— the segment id is element 0 (BR-020).- Each parser instance carries its own
resultslist and index sequence, so instances are single-use.*
Process flow¶
flowchart TD
Start([Raw EDI string]) --> Segs["Split on ~ (RemoveEmptyEntries)"]
Segs --> Loop[For each segment token]
Loop --> Elems["EdiDataElementParser.Parse: split on *"]
Elems --> Composite{Token contains colon?}
Composite -->|Yes| Comp["EdiCompositeDataElementParser.Parse<br>split on colon"]
Composite -->|No| Simple[Simple EdiDataElement]
Comp --> SetId["SegmentId = element 0"]
Simple --> SetId
SetId --> More{More segment tokens?}
More -->|Yes| Loop
More -->|No| EndOk([List of IEdiSegment returned])
Failure and edge-case behavior¶
- Empty segments produced by adjacent
~~are silently discarded byRemoveEmptyEntriesrather than becoming zero-elementEdiSegmentinstances (BR-018). - Reusing a single
EdiSegmentParser/EdiDataElementParser/EdiCompositeDataElementParserinstance across twoParsecalls accumulates results from both calls in the same internal list and index sequence, because each instance is single-use.*
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
- Common\SAIF.Common.Files\Edi\Core\Parsers\EdiSegmentParser.cs
- Common\SAIF.Common.Files\Edi\Core\Parsers\EdiDataElementParser.cs
- Common\SAIF.Common.Files\Edi\Core\Parsers\EdiCompositeDataElementParser.cs
- Common\SAIF.Common.Files\Edi\EdiRecordBase.cs