Splitting messages

Processing large files where all data is contained within a single message is possible by splitting it into multiple parts. The parser loads one message at a time when used in streaming mode, however, when this message is too large then the parser can be configured to load it in parts by matching a unique value within the message and splitting by it.

Note: Transaction splitting works only for loops at the first level right after the message root and the value to split by must not match any other segment of the same name within the message.

If you want to split the following message by the block of segments in the N1 loop...

EDI Segment Split

...set the fourth parameter of the Message attribute to the value to match by (using case sensitive String.StartsWith).

Set the fourth parameter of the Message attribute to the string to split by.

[Message("X12", "002040", "810", N1*)]
public class TS810 : EdiMessage

Each part retains the message name (transaction id), the control number and all other base properties of the original.

Message parts can be identified by the base property MessagePart which is greater than 0 and is incremented for every subsequent part.

Message parts have some limitations such as that they can't be published to AckMan and IsValid will produce unexpected results when applied to only a subset of the original segments. Although the messages themselves can't be validated correctly, you can specify an item in the spec for validation and execute Validate on that item.

To mark an item for validation set it to inherit from EdiItem.

[Group("N1")]
public class TS850_N1Loop : EdiItem

Once an item (this can be any of loop, segment, composite element) is marked with EdiItem, you can validate it in isolation by calling Validate. This will return a list of SegmentErrorContexts and the item will be valid if that list is empty.

To validate an item call Validate.

var n1Loops = ediItems.OfType<TS850>().Where(m => m.N1Loop1 != null).SelectMany(m => m.N1Loop1);
foreach (var n1Loop in n1Loops)
{
    var segmentContexts = n1Loop.Validate();
}