X12Writer Class
Properties Methods Events Configuration Settings Errors
The X12Writer class is optimized for X12 documents, providing a simple way to create X12 documents.
Syntax
class ipworksx12.X12Writer
Remarks
The class allows you to create a document from scratch. The class allows you to create an EDI document one segment at a time. Here's how a document would normally be created:
- Call load_schema to load the necessary schemas for the transactions that will be used.
- Specify where to write the output document by setting the output_file property or set_output_stream method, or set neither and check the output_data property.
- Create a new interchange start segment using the start_interchange_header method and set its properties using write_element_string and write_component_string.
- To write a basic element value to the current location, call the write_element_string 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 start_element and end_element methods, with write_component_string and repeat_element methods for writing the values. (Examples available below).
- Create a new functional group using start_functional_group_header and set its properties using write_element_string and write_component_string.
- Create a new transaction using start_transaction_header and set the properties for the header segment.
- Write all the data for the transaction by creating new data segments using start_segment and providing the path of the segment to create using the schema names of the loops and segments, like /N1Loop1/N1.
- Once you are done with the segment, call end_segment.
- Once you are done with the transaction, call create_transaction_footer.
- Once you are done with the functional group, call create_functional_group_footer.
- Once the interchange is complete, call create_interchange_footer.
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 class with short descriptions. Click on the links for further details.
file_write_mode | Controls how the output file is opened. |
output_data | Contains the output data. |
output_file | Specifies the name of the EDI file to write to. |
schema_format | The format of the schema file. |
suffix | What to append after each segment delimiter. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
compile_schema | Compiles an existing XSD schema into an optimized binary representation. |
config | Sets or retrieves a configuration setting. |
create_functional_group_footer | Closes the current functional group by writing its footer segment. |
create_interchange_footer | Closes the current interchange by writing its footer segment. |
create_transaction_footer | Closes the current transaction set by writing its footer segment. |
display_schema_info | Returns a string showing the structure of the schema defining the document. |
end_element | Finishes the current composite data element. |
end_segment | Ends writing the current segment. |
flush | Forces any pending segments to be written to the output stream without closing it. |
load_schema | Loads a schema file describing a Transaction Set. |
repeat_element | Adds a new repetition to the current element. |
reset | Resets the state of the control. |
skip_component | Moves to the next sub-element in the current composite element in the current segment. |
skip_element | Moves to the next data element in the current segment. |
start_element | Starts a new EDI composite data element on the current segment. |
start_functional_group_header | Creates a new EDI functional group header segment on the current document. |
start_interchange_header | Creates a new EDI Interchange header segment on the current document. |
start_segment | Creates a new EDI data segment on the current document. |
start_transaction_header | Creates a new EDI transaction set header on the current document. |
write_component_string | Sets the value of the next class within the current element in the current segment. |
write_element_string | Sets a value of the next element in the current segment to a simple value. |
write_transaction | Writes an entire transaction to the output. |
Event List
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
on_error | Information about errors during data delivery. |
on_output | Fires whenever a segment is complete. |
on_warning | Fires whenever a validation warning is encountered. |
Configuration Settings
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
ComponentDelimiter | The delimiter character to use to separate classes. |
EdifactSyntaxVersion | Changes the syntax version used for EDIFACT control segments. |
ElementDelimiter | The delimiter character to use to separate data elements. |
Encoding | The character encoding to be applied when reading and writing data. |
IncludeUNA | Whether to include the UNA segment in the output. |
ReleaseChar | The character to use to escape delimiters within values. |
RepetitionChar | The repetition character. |
SegmentDelimiter | The delimiter character to use to separate segments. |
StrictSchemaValidation | Specifies the behavior during schema validation. |
TransactionOnly | Ignores interchange and functional group validation, allowing you to build the transaction body. |
BuildInfo | Information about the product's build. |
CodePage | The system code page used for Unicode to Multibyte translations. |
LicenseInfo | Information about the current license. |
ProcessIdleEvents | Whether the class uses its internal event loop to process events when the main thread is idle. |
SelectWaitMillis | The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process. |
UseInternalSecurityAPI | Tells the class whether or not to use the system security libraries or an internal implementation. |