IPWorks EDIFACT 2020 JavaScript Edition

Questions / Feedback?

EDIFACTTranslator Class

Properties   Methods   Events   Configuration Settings   Errors  

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

Syntax

ipworksedifact.edifacttranslator()

Remarks

The class provides a way to convert EDIFACT to XML or JSON and vice versa.

Getting Started

The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. 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 LoadSchema 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 AddRenamingRule.

After calling Translate the resulting output will contain the EDI, XML or JSON data as defined by OutputFormat. If the output data is XML the ExportXMLSchema 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:
  • OutputFile
  • OutputData: The output data is written to this property if no other destination is specified.

Example - Translating EDIFACT to XML


Edifacttranslator translator = new Edifacttranslator();

translator.InputFormat = EdifacttranslatorInputFormats.ifEDIFACT;
translator.OutputFormat = EdifacttranslatorOutputFormats.ofXML;

translator.InputFile = "EDIFACT_D97A_INVOIC.edi";
translator.OutputFile = "EDIFACT_D97A_INVOIC.xml";

translator.SchemaFormat = EdifacttranslatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_D97A_INVOIC.json");

translator.Translate();

The code above creates an XML document with content like:

<Interchange Delimiters=":+.?*&apos;" xmlns="http://www.nsoftware.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Meta>
        <UNB1 type="Composite" desc="SYNTAX IDENTIFIER">
            <UNB1.1 desc="Syntax identifier">UNOB</UNB1.1>
            <UNB1.2 desc="Syntax version number">1</UNB1.2>
        </UNB1>
        <UNB2 type="Composite" desc="INTERCHANGE SENDER">
            <UNB2.1 desc="Interchange sender identification">WAYNE_TECH</UNB2.1>
        </UNB2>
        <UNB3 type="Composite" desc="INTERCHANGE RECIPIENT">
            <UNB3.1 desc="Interchange recipient identification">ACME</UNB3.1>
        </UNB3>
        <UNB4 type="Composite" desc="DATE AND TIME OF PREPARATION">
            <UNB4.1 desc="Date">160707</UNB4.1>
            <UNB4.2 desc="Time">1547</UNB4.2>
        </UNB4>
        <UNB5 desc="Interchange control reference">000000002</UNB5>
        <UNB6 type="Composite" desc="RECIPIENT&apos;S REFERENCE/PASSWORD DETAILS">
            <UNB6.1 desc="Recipient reference/password"/>
        </UNB6>
        <UNB7 desc="Application reference">1234</UNB7>
        <UNB8 desc="Processing priority code"/>
        <UNB9 desc="Acknowledgement request"/>
        <UNB10 desc="Interchange agreement identifier"/>
        <UNB11 desc="Test indicator">1</UNB11>
    </Meta>
    <TransactionSet>
        <TX-D97A-INVOIC type="TransactionSet">
            <Meta>
                <UNH1 desc="MESSAGE REFERENCE NUMBER">509010117</UNH1>
                <UNH2 type="Composite" desc="MESSAGE IDENTIFIER">
                    <UNH2.1 desc="Message type identifier">INVOIC</UNH2.1>
                    <UNH2.2 desc="Message type version number">D</UNH2.2>
                    <UNH2.3 desc="Message type release number">97A</UNH2.3>
                    <UNH2.4 desc="Controlling agency">UN</UNH2.4>
                </UNH2>
            </Meta>
            <BGM type="Segment">
                <BGM01 type="Composite" desc="DOCUMENT/MESSAGE NAME">
                    <BGM0101 desc="Document/message name, coded">380</BGM0101>
                    <BGM0102 desc="Code list qualifier"/>
                    <BGM0103 desc="Code list responsible agency, coded"/>
                    <BGM0104 desc="Document/message name">TAX INVOICE</BGM0104>
                </BGM01>
...                

Example - Translating EDIFACT to JSON


Edifacttranslator translator = new Edifacttranslator();

translator.InputFormat = EdifacttranslatorInputFormats.ifEDIFACT;
translator.OutputFormat = EdifacttranslatorOutputFormats.ofJSON;

translator.InputFile = "EDIFACT_D97A_INVOIC.edi";
translator.OutputFile = "EDIFACT_D97A_INVOIC.json";

translator.SchemaFormat = EdifacttranslatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_D97A_INVOIC.json");

translator.Translate();

The code above creates a JSON document with content like:

{
	"meta": {
		"type": "Interchange",
		"delimiters": ":+.?*'",
		"UNB1": {
			"type": "Composite",
			"desc": "SYNTAX IDENTIFIER",
			"UNB1.1": {
				"desc": "Syntax identifier",
				"value": "UNOB"
			},
			"UNB1.2": {
				"desc": "Syntax version number",
				"value": "1"
			}
		},
		"UNB2": {
			"type": "Composite",
			"desc": "INTERCHANGE SENDER",
			"UNB2.1": {
				"desc": "Interchange sender identification",
				"value": "WAYNE_TECH"
			}
		},
		"UNB3": {
			"type": "Composite",
			"desc": "INTERCHANGE RECIPIENT",
			"UNB3.1": {
				"desc": "Interchange recipient identification",
				"value": "ACME"
			}
		},
		"UNB4": {
			"type": "Composite",
			"desc": "DATE AND TIME OF PREPARATION",
			"UNB4.1": {
				"desc": "Date",
				"value": "160707"
			},
			"UNB4.2": {
				"desc": "Time",
				"value": "1547"
			}
		},
		"UNB5": {
			"desc": "Interchange control reference",
			"value": "000000002"
		},
		"UNB6": {
			"type": "Composite",
			"desc": "RECIPIENT'S REFERENCE\/PASSWORD DETAILS",
			"UNB6.1": {
				"desc": "Recipient reference\/password",
				"value": ""
			}
		},
		"UNB7": {
			"desc": "Application reference",
			"value": "1234"
		},
		"UNB8": {
			"desc": "Processing priority code",
			"value": ""
		},
		"UNB9": {
			"desc": "Acknowledgement request",
			"value": ""
		},
		"UNB10": {
			"desc": "Interchange agreement identifier",
			"value": ""
		},
		"UNB11": {
			"desc": "Test indicator",
			"value": "1"
		}
	},
	"transactionsets": [{
		"meta": {
			"type": "TransactionSet",
			"UNH1": {
				"desc": "MESSAGE REFERENCE NUMBER",
				"value": "509010117"
			},
			"UNH2": {
				"type": "Composite",
				"desc": "MESSAGE IDENTIFIER",
				"UNH2.1": {
					"desc": "Message type identifier",
					"value": "INVOIC"
				},
				"UNH2.2": {
					"desc": "Message type version number",
					"value": "D"
				},
				"UNH2.3": {
					"desc": "Message type release number",
					"value": "97A"
				},
				"UNH2.4": {
					"desc": "Controlling agency",
					"value": "UN"
				}
			}
		},
		"segments": [{
			"type": "Segment",
			"name": "BGM",
			"BGM01": {
				"type": "Composite",
				"desc": "DOCUMENT\/MESSAGE NAME",
				"BGM0101": {
					"desc": "Document\/message name, coded",
					"value": "380"
				},
				"BGM0102": {
					"desc": "Code list qualifier",
					"value": ""
				},
				"BGM0103": {
					"desc": "Code list responsible agency, coded",
					"value": ""
				},
				"BGM0104": {
					"desc": "Document\/message name",
					"value": "TAX INVOICE"
				}
			},
...            

Property List


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

InputDataThe data to translate.
InputFileThe file to translate.
InputFormatThe format of the input data.
OutputDataThe translated data.
OutputFileThe file to which the translated data will be written.
OutputFormatThe format of the output data.
OverwriteWhether to overwrite the file.
RenamingRuleThe rule defining how EDI elements are renamed when translating to XML or JSON.
RenamingRuleCountThe number of renaming rules.
RenamingRuleIndexThe index of the current renaming rule.
SchemaFormatThe format of the schema file.
SuffixWhat to append after each segment delimiter.
UseSchemaNameWhether 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.

AddRenamingRuleThis method adds a renaming rule to define how an EDI element is renamed when translating to XML.
ConfigSets or retrieves a configuration setting.
DisplaySchemaInfoReturns a string showing the structure of the schema defining the document.
ExportXMLSchemaExports a XML schema.
GenerateAckGenerates an EDI acknowledgement.
LoadRenamingRulesLoads a set of renaming rules from file.
LoadSchemaLoads a schema file describing a Transaction Set.
ResetResets the state of the control.
SaveRenamingRulesSaves 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.

EndFunctionalGroupFires whenever a control segment is read that marks the end of an interchange.
EndInterchangeFires whenever a control segment is read that marks the end of an interchange.
EndLoopFires when the end of a loop is detected in a transaction set.
EndTransactionFires whenever a control segment is read that marks the end of a transaction.
ErrorInformation about errors during data delivery.
ResolveSchemaFires whenever a new transaction set is encountered and no schema is found for it.
SegmentFires whenever a data segment in a transaction set is read.
StartFunctionalGroupFires whenever a control segment is read that marks the start of a functional group.
StartInterchangeFires whenever a control segment is read that marks the start of an interchange.
StartLoopFires when the starting of a loop is detected in a transaction set.
StartTransactionFires whenever a control segment is read that marks the start of a transaction.
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.
EDIStandardThe document format.
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.
IncludeUNAWhether to include the UNA segment in the output.
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.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

 
 
Copyright (c) 2021 /n software inc. - All rights reserved.
IPWorks EDIFACT 2020 JavaScript Edition - Version 20.0 [Build 7721]