IPWorks X12 2020 Python Edition

Questions / Feedback?

X12Translator Class

Properties   Methods   Events   Configuration Settings   Errors  

The X12Translator class is optimized for X12 translation, providing a simple way to convert X12 documents to and from XML or JSON.

Syntax

class ipworksx12.X12Translator

Remarks

The X12Translator class provides a simple way to convert X12 to XML or JSON and vice versa.

Getting Started

The class will convert a document from the format specified by input_format to the format specified by output_format. In practice this allows for converting to XML or JSON from EDI and vice versa.

Before translating from EDI to XML or JSON it is recommended to load a schema using the load_schema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML or JSON will include types and descriptions as element attributes which are useful for interpreting the data.

EDI elements may optionally be renamed when creating XML. To define how an element is renamed add a renaming rule by calling add_renaming_rule.

After calling translate the resulting output will contain the EDI, XML or JSON data as defined by output_format. If the output data is XML the export_xml_schema method may be called to export a schema (.xsd) defining the structure of a valid XML document. XML documents which adhere to this document may be translated from XML to EDI.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

Example - Translating X12 to XML


X12translator translator = new X12translator();
translator.InputFormat = X12translatorInputFormats.ifX12;
translator.OutputFormat = X12translatorOutputFormats.ofXML;

translator.InputFile = "810.edi";
translator.OutputFile = "X12_810.xml";

translator.UseSchemaName = true;

translator.SchemaFormat = X12translatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_00401_810.json");

translator.Translate();

The code above creates an XML document with content like:

<Interchange xmlns="http://www.nsoftware.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Meta>
        <ISA01 desc="Authorization Information Qualifier">00</ISA01>
        <ISA02 desc="Authorization Information">          </ISA02>
        <ISA03 desc="Security Information Qualifer">00</ISA03>
        <ISA04 desc="Security Information">          </ISA04>
        <ISA05 desc="Interchange ID Qualifier">14</ISA05>
        <ISA06 desc="Interchange Sender ID">060704780001900</ISA06>
        <ISA07 desc="Interchange ID Qualifier">ZZ</ISA07>
        <ISA08 desc="Interchange Receiver ID">HYNIXEDI       </ISA08>
        <ISA09 desc="Interchange Date">130428</ISA09>
        <ISA10 desc="Interchange Time">2033</ISA10>
        <ISA11 desc="Interchange Control Standards Identifier">U</ISA11>
        <ISA12 desc="Interchange Control Version Number Code">00401</ISA12>
        <ISA13 desc="Inter Control Number">000040161</ISA13>
        <ISA14 desc="Acknowlegment Requested Code">1</ISA14>
        <ISA15 desc="Interchange Usage Indicator Code">T</ISA15>
        <ISA16 desc="Component Element Separator">&gt;</ISA16>
    </Meta>
    <FunctionalGroup>
        <Meta>
            <GS01 desc="Functional Identifier Code">IN</GS01>
            <GS02 desc="Application Sender&apos;s Code">060704780500</GS02>
            <GS03 desc="Application Receiver&apos;s Code">HYNIXEDI</GS03>
            <GS04 desc="Date">20130428</GS04>
            <GS05 desc="Time">2033</GS05>
            <GS06 desc="Group Control Number">000040161</GS06>
            <GS07 desc="Responsible Agency Code">X</GS07>
            <GS08 desc="Version / Release / Industry Identifier Code">004010</GS08>
        </Meta>
        <TransactionSet>
            <TX-00401-810 type="TransactionSet">
                <Meta>
                    <ST01 desc="Transaction Set Identifier Code">810</ST01>
                    <ST02 desc="Transaction Set Control Number">0001</ST02>
                </Meta>
                <BIG type="Segment">
                    <BIG01 desc="Date">20090629</BIG01>
                    <BIG02 desc="Invoice Number">3003014445</BIG02>
                    <BIG03 desc="Date" xsi:nil="true"/>
                    <BIG04 desc="Purchase Order Number">0476553272</BIG04>
                    <BIG05 desc="Release Number" xsi:nil="true"/>
                    <BIG06 desc="Change Order Sequence Number" xsi:nil="true"/>
                    <BIG07 desc="Transaction Type Code">DR</BIG07>
                </BIG>
...                

Example - Translating X12 to JSON


X12translator translator = new X12translator();
translator.InputFormat = X12translatorInputFormats.ifX12;
translator.OutputFormat = X12translatorOutputFormats.ofJSON;

translator.InputFile = "810.edi";
translator.OutputFile = "X12_810.json";

translator.UseSchemaName = true;

translator.SchemaFormat = X12translatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_00401_810.json");

translator.Translate();

The code above creates a JSON document with content like:

{
	"meta": {
		"type": "Interchange",
		"ISA01": {
			"desc": "Authorization Information Qualifier",
			"value": "00"
		},
		"ISA02": {
			"desc": "Authorization Information",
			"value": "          "
		},
		"ISA03": {
			"desc": "Security Information Qualifer",
			"value": "00"
		},
		"ISA04": {
			"desc": "Security Information",
			"value": "          "
		},
		"ISA05": {
			"desc": "Interchange ID Qualifier",
			"value": "14"
		},
		"ISA06": {
			"desc": "Interchange Sender ID",
			"value": "060704780001900"
		},
		"ISA07": {
			"desc": "Interchange ID Qualifier",
			"value": "ZZ"
		},
		"ISA08": {
			"desc": "Interchange Receiver ID",
			"value": "HYNIXEDI       "
		},
		"ISA09": {
			"desc": "Interchange Date",
			"value": "130428"
		},
		"ISA10": {
			"desc": "Interchange Time",
			"value": "2033"
		},
		"ISA11": {
			"desc": "Interchange Control Standards Identifier",
			"value": "U"
		},
		"ISA12": {
			"desc": "Interchange Control Version Number Code",
			"value": "00401"
		},
		"ISA13": {
			"desc": "Inter Control Number",
			"value": "000040161"
		},
		"ISA14": {
			"desc": "Acknowlegment Requested Code",
			"value": "1"
		},
		"ISA15": {
			"desc": "Interchange Usage Indicator Code",
			"value": "T"
		},
		"ISA16": {
			"desc": "Component Element Separator",
			"value": ">"
		}
	},
	"functionalgroups": [{
		"meta": {
			"type": "FunctionalGroup",
			"GS01": {
				"desc": "Functional Identifier Code",
				"value": "IN"
			},
			"GS02": {
				"desc": "Application Sender's Code",
				"value": "060704780500"
			},
			"GS03": {
				"desc": "Application Receiver's Code",
				"value": "HYNIXEDI"
			},
			"GS04": {
				"desc": "Date",
				"value": "20130428"
			},
			"GS05": {
				"desc": "Time",
				"value": "2033"
			},
			"GS06": {
				"desc": "Group Control Number",
				"value": "000040161"
			},
			"GS07": {
				"desc": "Responsible Agency Code",
				"value": "X"
			},
			"GS08": {
				"desc": "Version \/ Release \/ Industry Identifier Code",
				"value": "004010"
			}
		},
		"transactionsets": [{
			"meta": {
				"type": "TransactionSet",
				"ST01": {
					"desc": "Transaction Set Identifier Code",
					"value": "810"
				},
				"ST02": {
					"desc": "Transaction Set Control Number",
					"value": "0001"
				}
			},
			"segments": [{
				"type": "Segment",
				"name": "BIG",
				"BIG01": {
					"desc": "Date",
					"value": "20090629"
				},
				"BIG02": {
					"desc": "Invoice Number",
					"value": "3003014445"
				},
				"BIG03": {
					"desc": "Date",
					"value": null
				},
				"BIG04": {
					"desc": "Purchase Order Number",
					"value": "0476553272"
				},
				"BIG05": {
					"desc": "Release Number",
					"value": null
				},
				"BIG06": {
					"desc": "Change Order Sequence Number",
					"value": null
				},
				"BIG07": {
					"desc": "Transaction Type Code",
					"value": "DR"
				}
			},
...            

Property List


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

input_dataThe data to translate.
input_fileThe file to translate.
input_formatThe format of the input data.
output_dataThe translated data.
output_fileThe file to which the translated data will be written.
output_formatThe format of the output data.
overwriteWhether to overwrite the file.
renaming_ruleThe rule defining how EDI elements are renamed when translating to XML or JSON.
renaming_rule_countThe number of renaming rules.
renaming_rule_indexThe index of the current renaming rule.
schema_formatThe format of the schema file.
suffixWhat to append after each segment delimiter.
use_schema_nameWhether the output XML uses element names based on name defined in the schema.

Method List


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

add_renaming_ruleThis method adds a renaming rule to define how an EDI element is renamed when translating to XML.
configSets or retrieves a configuration setting.
display_schema_infoReturns a string showing the structure of the schema defining the document.
export_xml_schemaExports a XML schema.
generate_ackGenerates an EDI acknowledgement.
load_renaming_rulesLoads a set of renaming rules from file.
load_schemaLoads a schema file describing a Transaction Set.
resetResets the state of the control.
save_renaming_rulesSaves the current renaming rule set to a file.
translateTranslates the specified data.

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_end_functional_groupFires whenever a control segment is read that marks the end of an interchange.
on_end_interchangeFires whenever a control segment is read that marks the end of an interchange.
on_end_loopFires when the end of a loop is detected in a transaction set.
on_end_transactionFires whenever a control segment is read that marks the end of a transaction.
on_errorInformation about errors during data delivery.
on_resolve_schemaFires whenever a new transaction set is encountered and no schema is found for it.
on_segmentFires whenever a data segment in a transaction set is read.
on_start_functional_groupFires whenever a control segment is read that marks the start of a functional group.
on_start_interchangeFires whenever a control segment is read that marks the start of an interchange.
on_start_loopFires when the starting of a loop is detected in a transaction set.
on_start_transactionFires whenever a control segment is read that marks the start of a transaction.
on_warningFires 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.

ComponentDelimiterThe delimiter character to use to separate classes.
CrossFieldValidationEnabledEnables cross-field validation rules.
ElementDelimiterThe delimiter character to use to separate data elements.
EncodingThe character encoding to be applied when reading and writing data.
IncludeEmptyElementsWhether to include empty data elements in a composite element.
IncludeFootersWhether to include footer information in the XML.
JSONElementPrefixAn optional prefix for reserved names when translating to JSON.
LastIXControlNumberThe control number of the most recently parsed interchange.
LastTransactionControlNumberThe control number of the most recently parsed transaction.
ReleaseCharThe character to use to escape delimiters within values.
RenamingRulesDataThe renaming rules data.
RepetitionCharThe repetition character.
SegmentDelimiterThe delimiter character to use to separate segments.
StrictSchemaValidationSpecifies the behavior during schema validation.
UseXMLCommentsWhether the human readable description is stored as an attribute or XML comments.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
ProcessIdleEventsWhether the class uses its internal event loop to process events when the main thread is idle.
SelectWaitMillisThe length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks X12 2020 Python Edition - Version 20.0 [Build 8155]