IPWorks EDI Translator 2022 .NET Edition
Version 22.0 [Build 8369]

X12Writer Component

Properties   Methods   Events   Config Settings   Errors  

The X12Writer component is optimized for X12 documents, providing a simple way to create X12 documents.

Syntax

nsoftware.IPWorksEDITranslator.X12writer

Remarks

The component allows you to create a document from scratch. The component allows you to create an EDI document one segment at a time. Here's how a document would normally be created:

  1. Call LoadSchema to load the necessary schemas for the transactions that will be used.
  2. Specify where to write the output document by setting the OutputFile property or SetOutputStream method, or set neither and check the OutputData property.
  3. Create a new interchange start segment using the StartInterchangeHeader method and set its properties using WriteElementString and WriteComponentString.
  4. To write a basic element value to the current location, call the WriteElementString method. For complex element values, there are two possibilities, elements which are split into components, and elements which repeat. To write these complex element values, use the StartElement and EndElement methods, with WriteComponentString and RepeatElement methods for writing the values. (Examples available below).
  5. Create a new functional group using StartFunctionalGroupHeader and set its properties using WriteElementString and WriteComponentString.
  6. Create a new transaction using StartTransactionHeader and set the properties for the header segment.
  7. Write all the data for the transaction by creating new data segments using StartSegment and providing the path of the segment to create using the schema names of the loops and segments, like /N1Loop1/N1.
  8. Once you are done with the segment, call EndSegment.
  9. Once you are done with the transaction, call CreateTransactionFooter.
  10. Once you are done with the functional group, call CreateFunctionalGroupFooter.
  11. Once the interchange is complete, call CreateInterchangeFooter.

Example X12Writer Code:

//Create an 810 //Start Interchange Header writer.StartInterchangeHeader("004010"); writer.WriteElementString("00"); writer.SkipElement(); writer.WriteElementString("00"); writer.SkipElement(); writer.WriteElementString("ZZ"); writer.WriteElementString("ACME "); writer.WriteElementString("ZZ"); writer.WriteElementString("WAYNE_TECH "); writer.WriteElementString("160707"); writer.WriteElementString("1544"); writer.WriteElementString("U"); writer.WriteElementString("00401"); writer.WriteElementString("000000006"); writer.WriteElementString("0"); writer.WriteElementString("T"); writer.WriteElementString(">"); //Start Functional Group writer.StartFunctionalGroupHeader(); writer.WriteElementString("IN"); writer.WriteElementString("ACME"); writer.WriteElementString("WAYNE_TECH"); writer.WriteElementString("20160707"); writer.WriteElementString("1544"); writer.WriteElementString("6"); writer.WriteElementString("T"); writer.WriteElementString("004010"); //Start Transaction Header writer.StartTransactionHeader("810"); writer.WriteElementString("810"); writer.WriteElementString("0001"); //Write the BIG segment writer.StartSegment("BIG"); writer.WriteElementString("20150708"); writer.WriteElementString("3003014445"); writer.SkipElement(); writer.WriteElementString("0476553272"); writer.SkipElement(); writer.SkipElement(); writer.WriteElementString("DR"); writer.EndElement(); //Write the CUR segment writer.StartSegment("CUR"); writer.WriteElementString("SE"); writer.WriteElementString("USD"); //Write the REF segment writer.StartSegment("REF"); writer.WriteElementString("8M"); writer.WriteElementString("0056");

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

FileWriteModeControls how the output file is opened.
OutputDataContains the output data.
OutputFileSpecifies the name of the EDI file to write to.
SchemaFormatThe format of the schema file.
SuffixWhat to append after each segment delimiter.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

CompileSchemaCompiles an existing XSD schema into an optimized binary representation.
ConfigSets or retrieves a configuration setting.
CreateFunctionalGroupFooterCloses the current functional group by writing its footer segment.
CreateInterchangeFooterCloses the current interchange by writing its footer segment.
CreateTransactionFooterCloses the current transaction set by writing its footer segment.
DisplaySchemaInfoReturns a string showing the structure of the schema defining the document.
EndElementFinishes the current composite data element.
EndSegmentEnds writing the current segment.
FlushForces any pending segments to be written to the output stream without closing it.
LoadSchemaLoads a schema file describing a Transaction Set.
LoadSchemaStreamLoads a schema stream describing a Transaction Set.
RepeatElementAdds a new repetition to the current element.
ResetResets the state of the control.
SetOutputStreamAn output stream to write the EDI data to.
SkipComponentMoves to the next sub-element in the current composite element in the current segment.
SkipElementMoves to the next data element in the current segment.
StartElementStarts a new EDI composite data element on the current segment
StartFunctionalGroupHeaderCreates a new EDI functional group header segment on the current document.
StartInterchangeHeaderCreates a new EDI Interchange header segment on the current document.
StartSegmentCreates a new EDI data segment on the current document.
StartTransactionHeaderCreates a new EDI transaction set header on the current document.
WriteComponentStringSets the value of the next component within the current element in the current segment.
WriteElementStringSets a value of the next element in the current segment to a simple value.
WriteTransactionWrites an entire transaction to the output.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorInformation about errors during data delivery.
OutputFires whenever a segment is complete.
WarningFires whenever a validation warning is encountered.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

CloseStreamAfterInterchangeControls when the output stream is closed.
ComponentDelimiterThe delimiter character to use to separate components.
EdifactSyntaxVersionChanges the syntax version used for EDIFACT control segments.
EDIStandardThe document format.
ElementDelimiterThe delimiter character to use to separate data elements.
EncodingThe character encoding to be applied when reading and writing data.
IncludeUNAWhether to include the UNA segment in the output.
ReleaseCharThe character to use to escape delimiters within values.
RepetitionCharThe repetition character.
SegmentDelimiterThe delimiter character to use to separate segments.
StrictSchemaValidationSpecifies the behavior during schema validation.
TransactionOnlyIgnores interchange and functional group validation, allowing you to build the transaction body.
BuildInfoInformation about the product's build.
GUIAvailableTells the component whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
UseFIPSCompliantAPITells the component whether or not to use FIPS certified APIs.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

FileWriteMode Property (X12Writer Component)

Controls how the output file is opened.

Syntax

public X12writerFileWriteModes FileWriteMode { get; set; }

enum X12writerFileWriteModes { fwmCreate, fwmOverwrite, fwmAppend }
Public Property FileWriteMode As X12writerFileWriteModes

Enum X12writerFileWriteModes fwmCreate fwmOverwrite fwmAppend End Enum

Default Value

0

Remarks

This property controls how the component will open the output file specified in OutputFile. Possible values are:

fwmCreate (0)Always create a new file. If the file already exists, an error will be raised.
fwmOverwrite (1)If the output file already exists, it will be overwritten.
fwmAppend (2)If the output file already exists, data will be appended to it.

OutputData Property (X12Writer Component)

Contains the output data.

Syntax

public string OutputData { get; }
public byte[] OutputDataB { get; }
Public ReadOnly Property OutputData As String
Public ReadOnly Property OutputDataB As Byte()

Default Value

""

Remarks

This property will be populated with the contents of the EDI data as output by the component when no OutputFile has been specified and SetOutputStream has not been called with a valid output stream.

This property is read-only.

OutputFile Property (X12Writer Component)

Specifies the name of the EDI file to write to.

Syntax

public string OutputFile { get; set; }
Public Property OutputFile As String

Default Value

""

Remarks

Set OutputFile before calling the StartInterchangeHeader method to write an EDI interchange to a file on disk.

SchemaFormat Property (X12Writer Component)

The format of the schema file.

Syntax

public X12writerSchemaFormats SchemaFormat { get; set; }

enum X12writerSchemaFormats { schemaAutomatic, schemaBinary, schemaBizTalk, schemaSEF, schemaBOTS, schemaAltova, schemaJSON }
Public Property SchemaFormat As X12writerSchemaFormats

Enum X12writerSchemaFormats schemaAutomatic schemaBinary schemaBizTalk schemaSEF schemaBOTS schemaAltova schemaJSON End Enum

Default Value

0

Remarks

Set SchemaFormat before calling the LoadSchema method to specify the loading schema format.

The following schema formats are supported:

0 (schemaAutomatic - default) The schema type is automatically determined based on file extension.
1 (schemaBinary) A binary schema that was previously compiled by calling CompileSchema.
2 (schemaBizTalk) BizTalk (XSD): http://msdn.microsoft.com/en-us/library/aa559426(v=BTS.70).aspx
3 (schemaSEF) TIBCO Standard Exchange Format (SEF): https://docs.tibco.com/products/tibco-foresight-edisim-6-18-0
5 (schemaAltova) Altova: http://www.altova.com/
6 (schemaJSON - recommended) ArcESB JSON: https://arc.cdata.com/

Suffix Property (X12Writer Component)

What to append after each segment delimiter.

Syntax

public X12writerSuffixes Suffix { get; set; }

enum X12writerSuffixes { suffixNone, suffixCR, suffixLF, suffixCRLF }
Public Property Suffix As X12writerSuffixes

Enum X12writerSuffixes suffixNone suffixCR suffixLF suffixCRLF End Enum

Default Value

0

Remarks

If Suffix is different from suffixNone, trailing (suffix) characters are appended after each segment delimiter. This is useful if you want to have a carriage return/line feed after each segment to make the document more readable.

This property is not available at design time.

CompileSchema Method (X12Writer Component)

Compiles an existing XSD schema into an optimized binary representation.

Syntax

public void CompileSchema(string xsdSchema, string binSchema);

Async Version
public async Task CompileSchema(string xsdSchema, string binSchema);
public async Task CompileSchema(string xsdSchema, string binSchema, CancellationToken cancellationToken);
Public Sub CompileSchema(ByVal XsdSchema As String, ByVal BinSchema As String)

Async Version
Public Sub CompileSchema(ByVal XsdSchema As String, ByVal BinSchema As String) As Task
Public Sub CompileSchema(ByVal XsdSchema As String, ByVal BinSchema As String, cancellationToken As CancellationToken) As Task

Remarks

This method parses XsdSchema and generates an optimized binary representation that is saved into the path referenced by BinSchema. Binary schemas are smaller and require less resources when loading later using LoadSchema

If the schema file does not exists or cannot be parsed as an EDI schema, the component throws an exception.

Config Method (X12Writer Component)

Sets or retrieves a configuration setting.

Syntax

public string Config(string configurationString);

Async Version
public async Task<string> Config(string configurationString);
public async Task<string> Config(string configurationString, CancellationToken cancellationToken);
Public Function Config(ByVal ConfigurationString As String) As String

Async Version
Public Function Config(ByVal ConfigurationString As String) As Task(Of String)
Public Function Config(ByVal ConfigurationString As String, cancellationToken As CancellationToken) As Task(Of String)

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

CreateFunctionalGroupFooter Method (X12Writer Component)

Closes the current functional group by writing its footer segment.

Syntax

public void CreateFunctionalGroupFooter();

Async Version
public async Task CreateFunctionalGroupFooter();
public async Task CreateFunctionalGroupFooter(CancellationToken cancellationToken);
Public Sub CreateFunctionalGroupFooter()

Async Version
Public Sub CreateFunctionalGroupFooter() As Task
Public Sub CreateFunctionalGroupFooter(cancellationToken As CancellationToken) As Task

Remarks

The CreateFunctionalGroupFooter method will write any existing segments to the output stream and then generate and write the functional group closing segment (GE or UNE). If there is an open transaction set, CreateFunctionalGroupFooter will first call CreateTransactionFooter to close it. If there is no functional group open, an exception will be thrown.

CreateInterchangeFooter Method (X12Writer Component)

Closes the current interchange by writing its footer segment.

Syntax

public void CreateInterchangeFooter();

Async Version
public async Task CreateInterchangeFooter();
public async Task CreateInterchangeFooter(CancellationToken cancellationToken);
Public Sub CreateInterchangeFooter()

Async Version
Public Sub CreateInterchangeFooter() As Task
Public Sub CreateInterchangeFooter(cancellationToken As CancellationToken) As Task

Remarks

The CreateInterchangeFooter method will write any existing segments to the output stream and then generate and write the interchange closing segment (IEA or UNZ). If there is an open transaction set, CreateInterchangeFooter will first call CreateTransactionFooter to close it. If there is an open functional group, CreateInterchangeFooter will first call CreateFunctionalGroupFooter to close it. If there is no interchange open, an exception will be thrown.

CreateTransactionFooter Method (X12Writer Component)

Closes the current transaction set by writing its footer segment.

Syntax

public void CreateTransactionFooter();

Async Version
public async Task CreateTransactionFooter();
public async Task CreateTransactionFooter(CancellationToken cancellationToken);
Public Sub CreateTransactionFooter()

Async Version
Public Sub CreateTransactionFooter() As Task
Public Sub CreateTransactionFooter(cancellationToken As CancellationToken) As Task

Remarks

The CreateTransactionFooter method will write any existing segments to the output stream and then generate and write the transaction set closing segment (SE or UNT). If there are no open transaction sets, an exception will be thrown.

DisplaySchemaInfo Method (X12Writer Component)

Returns a string showing the structure of the schema defining the document.

Syntax

public string DisplaySchemaInfo();

Async Version
public async Task<string> DisplaySchemaInfo();
public async Task<string> DisplaySchemaInfo(CancellationToken cancellationToken);
Public Function DisplaySchemaInfo() As String

Async Version
Public Function DisplaySchemaInfo() As Task(Of String)
Public Function DisplaySchemaInfo(cancellationToken As CancellationToken) As Task(Of String)

Remarks

After calling LoadSchema this may be called to obtain information about the structure of the schema defining the document. If the desired XPath is not known this helps determine the structure so that the correct XPath can be built.

Note: A valid schema must be loaded via LoadSchema.

For instance: Console.WriteLine(component.DisplaySchemaInfo()); Will output text like:

UNH[0,1]
  BGM[0,1]
  DTM[0,35]
  PAI[0,1]
  ALI[0,5]
  IMD[0,1]
  FTX[0,10]
  LOC[0,10]
  GIS[0,10]
  DGS[0,1]
  RFFLoop1[0,99]
    RFF[0,1]
    DTM_2[0,5]
    GIR[0,5]
    LOC_2[0,2]
    MEA[0,5]
    QTY[0,2]
    FTX_2[0,5]
    MOA[0,2]
  NADLoop1[0,99]
    NAD[0,1]
    LOC_3[0,25]
    FII[0,5]
    RFFLoop2[0,9999]
      RFF_2[0,1]
      DTM_3[0,5]
    DOCLoop1[0,5]
      DOC[0,1]
      DTM_4[0,5]
    CTALoop1[0,5]
      CTA[0,1]
      COM[0,5]
  TAXLoop1[0,5]
    TAX[0,1]
    MOA_2[0,1]
    LOC_4[0,5]
  CUXLoop1[0,5]
    CUX[0,1]
    DTM_5[0,5]
  PATLoop1[0,10]
    PAT[0,1]
    DTM_6[0,5]
    PCD[0,1]
    MOA_3[0,1]
    PAI_2[0,1]
    FII_2[0,1]
  TDTLoop1[0,10]
    TDT[0,1]
    TSR[0,1]
    LOCLoop1[0,10]
      LOC_5[0,1]
      DTM_7[0,5]
    RFFLoop3[0,9999]
      RFF_3[0,1]
      DTM_8[0,5]
  TODLoop1[0,5]
    TOD[0,1]
    LOC_6[0,2]
  PACLoop1[0,1000]
    PAC[0,1]
    MEA_2[0,5]
    EQD[0,1]
    PCILoop1[0,5]
      PCI[0,1]
      RFF_4[0,1]
      DTM_9[0,5]
      GIN[0,5]
  ALCLoop1[0,9999]
    ALC[0,1]
    ALI_2[0,5]
    FTX_3[0,1]
    RFFLoop4[0,5]
      RFF_5[0,1]
      DTM_10[0,5]
    QTYLoop1[0,1]
      QTY_2[0,1]
      RNG[0,1]
    PCDLoop1[0,1]
      PCD_2[0,1]
      RNG_2[0,1]
    MOALoop1[0,2]
      MOA_4[0,1]
      RNG_3[0,1]
      CUX_2[0,1]
      DTM_11[0,1]
    RTELoop1[0,1]
      RTE[0,1]
      RNG_4[0,1]
    TAXLoop2[0,5]
      TAX_2[0,1]
      MOA_5[0,1]
  RCSLoop1[0,100]
    RCS[0,1]
    RFF_6[0,5]
    DTM_12[0,5]
    FTX_4[0,5]
  AJTLoop1[0,1]
    AJT[0,1]
    FTX_5[0,5]
  INPLoop1[0,1]
    INP[0,1]
    FTX_6[0,5]
  LINLoop1[0,9999999]
    LIN[0,1]
    PIA[0,25]
    IMD_2[0,10]
    MEA_3[0,5]
    QTY_3[0,5]
    PCD_3[0,1]
    ALI_3[0,5]
    DTM_13[0,35]
    GIN_2[0,1000]
    GIR_2[0,1000]
    QVR[0,1]
    EQD_2[0,1]
    FTX_7[0,5]
    DGS_2[0,1]
    MOALoop2[0,10]
      MOA_6[0,1]
      CUX_3[0,1]
    PATLoop2[0,10]
      PAT_2[0,1]
      DTM_14[0,5]
      PCD_4[0,1]
      MOA_7[0,1]
    PRILoop1[0,25]
      PRI[0,1]
      CUX_4[0,1]
      APR[0,1]
      RNG_5[0,1]
      DTM_15[0,5]
    RFFLoop5[0,10]
      RFF_7[0,1]
      DTM_16[0,5]
    PACLoop2[0,10]
      PAC_2[0,1]
      MEA_4[0,10]
      EQD_3[0,1]
      PCILoop2[0,10]
        PCI_2[0,1]
        RFF_8[0,1]
        DTM_17[0,5]
        GIN_3[0,10]
    LOCLoop2[0,9999]
      LOC_7[0,1]
      QTY_4[0,100]
      DTM_18[0,5]
    TAXLoop3[0,99]
      TAX_3[0,1]
      MOA_8[0,1]
      LOC_8[0,5]
    NADLoop2[0,99]
      NAD_2[0,1]
      LOC_9[0,5]
      RFFLoop6[0,5]
        RFF_9[0,1]
        DTM_19[0,5]
      DOCLoop2[0,5]
        DOC_2[0,1]
        DTM_20[0,5]
      CTALoop2[0,5]
        CTA_2[0,1]
        COM_2[0,5]
    ALCLoop2[0,30]
      ALC_2[0,1]
      ALI_4[0,5]
      DTM_21[0,5]
      FTX_8[0,1]
      QTYLoop2[0,1]
        QTY_5[0,1]
        RNG_6[0,1]
      PCDLoop2[0,1]
        PCD_5[0,1]
        RNG_7[0,1]
      MOALoop3[0,2]
        MOA_9[0,1]
        RNG_8[0,1]
        CUX_5[0,1]
        DTM_22[0,1]
      RTELoop2[0,1]
        RTE_2[0,1]
        RNG_9[0,1]
      TAXLoop4[0,5]
        TAX_4[0,1]
        MOA_10[0,1]
    TDTLoop2[0,10]
      TDT_2[0,1]
      LOCLoop3[0,10]
        LOC_10[0,1]
        DTM_23[0,5]
    TODLoop2[0,5]
      TOD_2[0,1]
      LOC_11[0,2]
    RCSLoop2[0,100]
      RCS_2[0,1]
      RFF_10[0,5]
      DTM_24[0,5]
      FTX_9[0,5]
    GISLoop1[0,10]
      GIS_2[0,1]
      RFF_11[0,1]
      DTM_25[0,5]
      GIR_3[0,5]
      LOC_12[0,2]
      MEA_5[0,5]
      QTY_6[0,2]
      FTX_10[0,5]
      MOA_11[0,2]
  UNS[0,1]
  CNT[0,10]
  MOALoop4[0,100]
    MOA_12[0,1]
    RFFLoop7[0,1]
      RFF_12[0,1]
      DTM_26[0,5]
  TAXLoop5[0,10]
    TAX_5[0,1]
    MOA_13[0,2]
  ALCLoop3[0,15]
    ALC_3[0,1]
    ALI_5[0,1]
    MOA_14[0,2]
    FTX_11[0,1]
  UNT[0,1]

EndElement Method (X12Writer Component)

Finishes the current composite data element.

Syntax

public void EndElement();

Async Version
public async Task EndElement();
public async Task EndElement(CancellationToken cancellationToken);
Public Sub EndElement()

Async Version
Public Sub EndElement() As Task
Public Sub EndElement(cancellationToken As CancellationToken) As Task

Remarks

Call EndElement once you've written all components in an element started with StartElement. You should not call this if you wrote a simple element using WriteElementString

EndSegment Method (X12Writer Component)

Ends writing the current segment.

Syntax

public void EndSegment();

Async Version
public async Task EndSegment();
public async Task EndSegment(CancellationToken cancellationToken);
Public Sub EndSegment()

Async Version
Public Sub EndSegment() As Task
Public Sub EndSegment(cancellationToken As CancellationToken) As Task

Remarks

EndSegment terminates writing the current segment and flushes it to the output stream/file.

You should call EndSegment to close a segment started with StartSegment, StartInterchangeHeader, StartFunctionalGroupHeader or StartTransactionHeader.

Flush Method (X12Writer Component)

Forces any pending segments to be written to the output stream without closing it.

Syntax

public void Flush();

Async Version
public async Task Flush();
public async Task Flush(CancellationToken cancellationToken);
Public Sub Flush()

Async Version
Public Sub Flush() As Task
Public Sub Flush(cancellationToken As CancellationToken) As Task

Remarks

The Flush method forces the component to write the last created segment to the output stream and then flush the output stream.

LoadSchema Method (X12Writer Component)

Loads a schema file describing a Transaction Set.

Syntax

public void LoadSchema(string fileName);

Async Version
public async Task LoadSchema(string fileName);
public async Task LoadSchema(string fileName, CancellationToken cancellationToken);
Public Sub LoadSchema(ByVal FileName As String)

Async Version
Public Sub LoadSchema(ByVal FileName As String) As Task
Public Sub LoadSchema(ByVal FileName As String, cancellationToken As CancellationToken) As Task

Remarks

This method parses the File and loads it into an internal schema list. The component will attempt to automatically detect the SchemaFormat.

If the schema file does not exist or cannot be parsed as an EDI schema, the component throws an exception.

LoadSchemaStream Method (X12Writer Component)

Loads a schema stream describing a Transaction Set.

Syntax

public void LoadSchemaStream(System.IO.Stream schemaStream);

Async Version
public async Task LoadSchemaStream(System.IO.Stream schemaStream);
public async Task LoadSchemaStream(System.IO.Stream schemaStream, CancellationToken cancellationToken);
Public Sub LoadSchemaStream(ByVal SchemaStream As System.IO.Stream)

Async Version
Public Sub LoadSchemaStream(ByVal SchemaStream As System.IO.Stream) As Task
Public Sub LoadSchemaStream(ByVal SchemaStream As System.IO.Stream, cancellationToken As CancellationToken) As Task

Remarks

Parses Stream and loads it into an internal schema list. The SchemaFormat property must be set before calling this method.

The following SchemaFormat values are supported when calling this method:

  • schemaBinary
  • schemaBizTalk
  • schemaSEF
All other schema formats are unsupported when using this method. LoadSchema may be used if an unsupported schema format is required.

RepeatElement Method (X12Writer Component)

Adds a new repetition to the current element.

Syntax

public void RepeatElement();

Async Version
public async Task RepeatElement();
public async Task RepeatElement(CancellationToken cancellationToken);
Public Sub RepeatElement()

Async Version
Public Sub RepeatElement() As Task
Public Sub RepeatElement(cancellationToken As CancellationToken) As Task

Remarks

RepeatElement is used to write repeated data elements in supporting version of X12 or EDIFACT. To use it, first write the first repetition of the simple or composite data element and then call RepeatElement to repeat it, then write again.

Example: Repeating a simple data element: EDIWriter writer = new EDIWriter(); ... writer.StartSegment("Tag"); ... writer.WriteElementString("R1_1"); writer.RepeatElement(); writer.WriteElementString("R1_2"); writer.RepeatElement(); writer.WriteElementString("R1_3"); ... writer.EndSegment();

Example: Repeating a composite data element: EDIWriter writer = new EDIWriter(); ... writer.StartSegment("Tag"); ... writer.StartElement(); writer.WriteComponentString("C1_1"); writer.WriteComponentString("C2_1"); writer.RepeatElement(); writer.WriteComponentString("C1_2"); writer.WriteComponentString("C2_2"); writer.RepeatElement(); writer.WriteComponentString("C1_3"); writer.EndElement(); ... writer.EndSegment();

Reset Method (X12Writer Component)

Resets the state of the control.

Syntax

public void Reset();

Async Version
public async Task Reset();
public async Task Reset(CancellationToken cancellationToken);
Public Sub Reset()

Async Version
Public Sub Reset() As Task
Public Sub Reset(cancellationToken As CancellationToken) As Task

Remarks

Resets the state of the writer. If a document has been partially written already, it will not be closed correctly and the write process will be aborted.

SetOutputStream Method (X12Writer Component)

An output stream to write the EDI data to.

Syntax

public void SetOutputStream(System.IO.Stream outputStream);

Async Version
public async Task SetOutputStream(System.IO.Stream outputStream);
public async Task SetOutputStream(System.IO.Stream outputStream, CancellationToken cancellationToken);
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream)

Async Version
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream) As Task
Public Sub SetOutputStream(ByVal OutputStream As System.IO.Stream, cancellationToken As CancellationToken) As Task

Remarks

Call SetOutputStream with a valid output stream before calling the StartInterchangeHeader method to write an EDI interchange directly to a stream.

SkipComponent Method (X12Writer Component)

Moves to the next sub-element in the current composite element in the current segment.

Syntax

public void SkipComponent();

Async Version
public async Task SkipComponent();
public async Task SkipComponent(CancellationToken cancellationToken);
Public Sub SkipComponent()

Async Version
Public Sub SkipComponent() As Task
Public Sub SkipComponent(cancellationToken As CancellationToken) As Task

Remarks

SkipComponent can be used to avoid providing a value for the current sub-element in the opened composite element within the current segment.

If the sub-element already has a value (such as one provided by default by the component), said value will not be overwritten.

SkipElement Method (X12Writer Component)

Moves to the next data element in the current segment.

Syntax

public void SkipElement();

Async Version
public async Task SkipElement();
public async Task SkipElement(CancellationToken cancellationToken);
Public Sub SkipElement()

Async Version
Public Sub SkipElement() As Task
Public Sub SkipElement(cancellationToken As CancellationToken) As Task

Remarks

SkipElement can be used to avoid providing a value for the current element in the current segment.

If the element already has a value (such as one provided by default by the component), said value will not be overwritten.

StartElement Method (X12Writer Component)

Starts a new EDI composite data element on the current segment

Syntax

public void StartElement();

Async Version
public async Task StartElement();
public async Task StartElement(CancellationToken cancellationToken);
Public Sub StartElement()

Async Version
Public Sub StartElement() As Task
Public Sub StartElement(cancellationToken As CancellationToken) As Task

Remarks

When called, a new composite data element is created in the current segment. You can then call WriteComponentString one or more times to write the individual components or subelements that make up this composite.

Call EndElement once you've written all components in this element.

StartFunctionalGroupHeader Method (X12Writer Component)

Creates a new EDI functional group header segment on the current document.

Syntax

public void StartFunctionalGroupHeader();

Async Version
public async Task StartFunctionalGroupHeader();
public async Task StartFunctionalGroupHeader(CancellationToken cancellationToken);
Public Sub StartFunctionalGroupHeader()

Async Version
Public Sub StartFunctionalGroupHeader() As Task
Public Sub StartFunctionalGroupHeader(cancellationToken As CancellationToken) As Task

Remarks

When called, a new functional group start (GS or UNG) segment is created and set as the current segment. You should then set the values on said segment before adding a new transaction set within the document.

StartInterchangeHeader Method (X12Writer Component)

Creates a new EDI Interchange header segment on the current document.

Syntax

public void StartInterchangeHeader(string version);

Async Version
public async Task StartInterchangeHeader(string version);
public async Task StartInterchangeHeader(string version, CancellationToken cancellationToken);
Public Sub StartInterchangeHeader(ByVal Version As String)

Async Version
Public Sub StartInterchangeHeader(ByVal Version As String) As Task
Public Sub StartInterchangeHeader(ByVal Version As String, cancellationToken As CancellationToken) As Task

Remarks

When called, a new interchange start (ISA or UNB) segment is created and set as the current segment. You should then set the values on said segment before creating a functional group or a new transaction set within the document.

StartSegment Method (X12Writer Component)

Creates a new EDI data segment on the current document.

Syntax

public void StartSegment(string segmentType);

Async Version
public async Task StartSegment(string segmentType);
public async Task StartSegment(string segmentType, CancellationToken cancellationToken);
Public Sub StartSegment(ByVal SegmentType As String)

Async Version
Public Sub StartSegment(ByVal SegmentType As String) As Task
Public Sub StartSegment(ByVal SegmentType As String, cancellationToken As CancellationToken) As Task

Remarks

When called, a new data segment is created in the current transaction and set as the current segment. You can then set the values on said segment. Creating a new data segment automatically writes the previous current segment to the output stream.

The SegmentType argument specifies the type of data segment to create, using an XPath-like syntax, based on the transaction set schema. For example, to create a new N1 segment on the first N1 loop, specify "/N1Loop1/N1".

It's important to realize that segments must be created in the same order they should appear on the target EDI document. The EDIWriter component doesn't automatically enforce ordering rules, nor does it force the document to reorder segments in loops automatically.

StartTransactionHeader Method (X12Writer Component)

Creates a new EDI transaction set header on the current document.

Syntax

public void StartTransactionHeader(string code);

Async Version
public async Task StartTransactionHeader(string code);
public async Task StartTransactionHeader(string code, CancellationToken cancellationToken);
Public Sub StartTransactionHeader(ByVal Code As String)

Async Version
Public Sub StartTransactionHeader(ByVal Code As String) As Task
Public Sub StartTransactionHeader(ByVal Code As String, cancellationToken As CancellationToken) As Task

Remarks

When called, a new transaction set start (ST or UNH) segment is created and set as the current segment. You should then set the values on said segment before adding creating transaction data segments.

The Code argument should specify the transaction code you want to create (for example, "850" or "INVOIC"). This value, together with the EDI specification and the version provided in the StartInterchangeHeader method are used to locate a matching transaction set schema on the components schema cache. You must make sure that a corresponding schema has been successfully loaded into the component by using the LoadSchema method before trying to call StartTransactionHeader.

WriteComponentString Method (X12Writer Component)

Sets the value of the next component within the current element in the current segment.

Syntax

public void WriteComponentString(string value);

Async Version
public async Task WriteComponentString(string value);
public async Task WriteComponentString(string value, CancellationToken cancellationToken);
Public Sub WriteComponentString(ByVal Value As String)

Async Version
Public Sub WriteComponentString(ByVal Value As String) As Task
Public Sub WriteComponentString(ByVal Value As String, cancellationToken As CancellationToken) As Task

Remarks

Use the WriteComponentString method to specify a value for an individual component within a composite data element.

To write an entire composite data element, first call the StartElement method, then do one or more calls to WriteComponentString. Finish the composite element by calling the EndElement method.

WriteElementString Method (X12Writer Component)

Sets a value of the next element in the current segment to a simple value.

Syntax

public void WriteElementString(string value);

Async Version
public async Task WriteElementString(string value);
public async Task WriteElementString(string value, CancellationToken cancellationToken);
Public Sub WriteElementString(ByVal Value As String)

Async Version
Public Sub WriteElementString(ByVal Value As String) As Task
Public Sub WriteElementString(ByVal Value As String, cancellationToken As CancellationToken) As Task

Remarks

Use the WriteElementString method to specify a value for the next data element with simple content on the current segment.

To write a composite data element, even if it has a single sub-element, use the StartElement and WriteComponentString methods instead.

WriteTransaction Method (X12Writer Component)

Writes an entire transaction to the output.

Syntax

public void WriteTransaction(string value);

Async Version
public async Task WriteTransaction(string value);
public async Task WriteTransaction(string value, CancellationToken cancellationToken);
Public Sub WriteTransaction(ByVal Value As String)

Async Version
Public Sub WriteTransaction(ByVal Value As String) As Task
Public Sub WriteTransaction(ByVal Value As String, cancellationToken As CancellationToken) As Task

Remarks

Use the WriteTransaction method when you have generated a complete transaction outside of the component and want to include it in the document being created by this instance.

No validation is done on the contents of the Value parameter. You must ensure the transaction data is valid and matches the same conventions (delimiters, etc) being used in this document.

Error Event (X12Writer Component)

Information about errors during data delivery.

Syntax

public event OnErrorHandler OnError;

public delegate void OnErrorHandler(object sender, X12writerErrorEventArgs e);

public class X12writerErrorEventArgs : EventArgs {
  public int ErrorCode { get; }
  public string Description { get; }
}
Public Event OnError As OnErrorHandler

Public Delegate Sub OnErrorHandler(sender As Object, e As X12writerErrorEventArgs)

Public Class X12writerErrorEventArgs Inherits EventArgs
  Public ReadOnly Property ErrorCode As Integer
  Public ReadOnly Property Description As String
End Class

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Output Event (X12Writer Component)

Fires whenever a segment is complete.

Syntax

public event OnOutputHandler OnOutput;

public delegate void OnOutputHandler(object sender, X12writerOutputEventArgs e);

public class X12writerOutputEventArgs : EventArgs {
  public string OutputData { get; }
public byte[] OutputDataB { get; } }
Public Event OnOutput As OnOutputHandler

Public Delegate Sub OnOutputHandler(sender As Object, e As X12writerOutputEventArgs)

Public Class X12writerOutputEventArgs Inherits EventArgs
  Public ReadOnly Property OutputData As String
Public ReadOnly Property OutputDataB As Byte() End Class

Remarks

The Output event will fire when the writer completes a new segment and writes data to the output stream or buffer. The Data parameter contains the data bytes.

Warning Event (X12Writer Component)

Fires whenever a validation warning is encountered.

Syntax

public event OnWarningHandler OnWarning;

public delegate void OnWarningHandler(object sender, X12writerWarningEventArgs e);

public class X12writerWarningEventArgs : EventArgs {
  public int WarnCode { get; }
  public string Message { get; }
  public int SegmentNumber { get; }
  public string SegmentTag { get; }
  public string SegmentErrorCode { get; }
  public string ElementErrorCode { get; }
  public int ElementPosition { get; }
}
Public Event OnWarning As OnWarningHandler

Public Delegate Sub OnWarningHandler(sender As Object, e As X12writerWarningEventArgs)

Public Class X12writerWarningEventArgs Inherits EventArgs
  Public ReadOnly Property WarnCode As Integer
  Public ReadOnly Property Message As String
  Public ReadOnly Property SegmentNumber As Integer
  Public ReadOnly Property SegmentTag As String
  Public ReadOnly Property SegmentErrorCode As String
  Public ReadOnly Property ElementErrorCode As String
  Public ReadOnly Property ElementPosition As Integer
End Class

Remarks

The Warning event will fire if a validation error is encountered when writing a new segment to the output document. The WarnCode parameter contains the type of warning encountered. Message is a textual description of the problem. SegmentNumber is the index of the segment where the problem was found.

0 The component is not required but is present.
1 Invalid segment count.
2 Invalid transaction count.
3 Invalid group count.
4 Invalid interchange control number.
5 Invalid group control number.
6 Invalid transaction control number.
10 A required data element is missing.
11 Invalid field length.
12 Invalid field value.
13 A required component is missing.
14 The data element is not defined but is present.
30 Required segment is missing.
31 Required loop is missing.
32 Occurrences exceeds the schema defined limit.
33 Occurrences is less than the schema defined minimum.
40 Paired rule validation failed, the pair of elements must be present.
41 At least one of element is required, see message for list of elements.
42 Exclusion validation failed, only one of the elements can be present.
43 Conditional rule validation failed.
44 List conditional rule validation failed.
45 First then none validation failed. The presence of an element requires that other specific elements must not be present.
46 Only one or none of the elements can be present.

Config Settings (X12Writer Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

X12Writer Config Settings

CloseStreamAfterInterchange:   Controls when the output stream is closed.

If True, the component will close the output stream when CreateInterchangeFooter is called. If false, the stream is left open and Flush must be called to ensure all output has been written to the stream. The default value is false.

ComponentDelimiter:   The delimiter character to use to separate components.

When set, this changes the default delimiter to use to separate components within a data element. The default value depends on the EDI specification being used.

EdifactSyntaxVersion:   Changes the syntax version used for EDIFACT control segments.

Can be a number from 1 to 4. The default value is 1.

EDIStandard:   The document format.

This property specifies standard that the document follows. Possible values are:

  • 1 (EDIFACT - default)
  • 3 (TRADACOMS)

ElementDelimiter:   The delimiter character to use to separate data elements.

When set, this changes the default delimiter to use to separate data elements within a segment. The default value depends on the EDI specification being used.

Encoding:   The character encoding to be applied when reading and writing data.

If the data contains non-ASCII characters this setting should be specified so characters are properly preserved. This value should be set to a valid character set such as "UTF-8" or "ISO-8859-1".

IncludeUNA:   Whether to include the UNA segment in the output.

This setting determines whether the UNA segment is included in the EDIFACT output. If False, no Service String Advice (UNA) segment will be generated for EDIFACT interchanges. The default value is True.

ReleaseChar:   The character to use to escape delimiters within values.

When set, this changes the default escape character. The default value depends on the EDI specification being used.

RepetitionChar:   The repetition character.

When set, this changes the default repetition character. The default value depends on the EDI specification being used.

SegmentDelimiter:   The delimiter character to use to separate segments.

When set, this changes the default delimiter to use to separate segments within an EDI document. The default value depends on the EDI specification being used.

StrictSchemaValidation:   Specifies the behavior during schema validation.

This setting specifies what happens when performing schema validation and a validation warning occurs. By default this value is set to 1 (Warn) and the Warning event will fire, but processing will not stop. See the WarnCode parameter list in the Warning event for details about possible validation warnings. Possible values for this setting are:

0 (Ignore) All validation warnings will be ignored. Warning will not fire with warnings.
1 (Warn - default) The Warning event will fire with all validation warnings.
2 (Error) All validation warnings are treated as errors and will cause an exception. Processing will stop immediately.

TransactionOnly:   Ignores interchange and functional group validation, allowing you to build the transaction body.

When set to true, interchange and functional group headers will not be required. This allows building of the transaction level of an EDIFact document without specifying a document type.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Tells the component whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the component does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
UseFIPSCompliantAPI:   Tells the component whether or not to use FIPS certified APIs.

When set to true, the component will utilize the underlying operating system's certified APIs. Java editions, regardless of OS, utilize Bouncy Castle FIPS, while all the other Windows editions make use of Microsoft security libraries.

FIPS mode can be enabled by setting the UseFIPSCompliantAPI configuration setting to true. This is a static setting which applies to all instances of all components of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.

For more details please see the FIPS 140-2 Compliance article.

Note: This setting is only applicable on Windows.

UseInternalSecurityAPI:   Tells the component whether or not to use the system security libraries or an internal implementation.

By default the component will use the system security libraries to perform cryptographic functions where applicable. When set to false calls to unmanaged code will be made. In certain environments this is not desirable. To use a completely managed security implementation set this setting to true. Setting this to true tells the component to use the internal implementation instead of using the system's security API.

Note: This setting is static. The value set is applicable to all components used in the application.

When this value is set the product's system DLL is no longer required as a reference, as all unmanaged code is stored in that file.

Trappable Errors (X12Writer Component)

X12Writer Errors

1000   Input/Output error
1001   No stream or file name were specified for the component
1002   Unexpected end of file (EOF).
1003   Segment not found.
1004   Segment not found in schema.
1005   Schema not found.
1010   Invalid Writer state.
1011   Segment does not have the specified element or component.
1044   Error while reading schema file.
1099   Unexpected error.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks EDI Translator 2022 .NET Edition - Version 22.0 [Build 8369]