EDIFACTTranslator Class
Properties Methods Events Config Settings Errors
The EDIFACTTranslator class converts EDIFACT data to XML and back, streamlining translation between formats.
Class Name
EDISDK_EDIFACTTranslator
Procedural Interface
edisdk_edifacttranslator_open(); edisdk_edifacttranslator_close($res); edisdk_edifacttranslator_register_callback($res, $id, $function); edisdk_edifacttranslator_get_last_error($res); edisdk_edifacttranslator_get_last_error_code($res); edisdk_edifacttranslator_set($res, $id, $index, $value); edisdk_edifacttranslator_get($res, $id, $index); edisdk_edifacttranslator_do_config($res, $configurationstring); edisdk_edifacttranslator_do_loadschema($res, $fileordata, $messagename); edisdk_edifacttranslator_do_reset($res); edisdk_edifacttranslator_do_translate($res);
Remarks
The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. This allows for converting to XML from EDI and vice versa.
Before translating from EDI to XML 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 will include types and descriptions as element attributes which are useful for interpreting the data.
After calling Translate the resulting output will contain the EDI or XML data as defined by OutputFormat.
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.
Property List
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
| DelimiterComponent | The character used to separate the classes in a composite element. |
| DelimiterDecimal | The character used to separate the integer portion of a numeric value from the fractional portion. |
| DelimiterElement | The delimiter used to separate elements within a segment. |
| DelimiterRelease | The character used to escape other characters within a property. |
| DelimiterRepetition | The character used to indicate a repeating element or class. |
| DelimiterSegment | The character used to terminate a segment. |
| FileWriteMode | Determines how the output file is opened for writing. |
| InputData | The EDI message, specified as a string. |
| InputFile | The file containing the EDI message. |
| InputFormat | The format of the input data. |
| OutputData | The translated EDI data. |
| OutputFile | The name of the file to write the translated EDI data to. |
| OutputFormat | The format of the output data. |
| SegmentSuffix | The suffix that is appended to the end of a segment. |
Method List
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
| Config | Sets or retrieves a configuration setting. |
| LoadSchema | Loads schema information from a file or string data. |
| Reset | Resets all properties to their default values. |
| Translate | Translates 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.
| Error | Fires when an error occurs during message processing. Normally, the class fails with an error. |
| ResolveSchema | Fires whenever a new EDIFACT message is encountered and no schema is found for it. |
| ValidateWarning | Fires to warn about validation errors. |
Config Settings
The following is a list of config settings for the class with short descriptions. Click on the links for further details.
| CloseStreamAfterTranslate | Whether to close the output stream after translation. |
| Encoding | The character encoding to use for the output EDIFACT document. |
| UseDescriptions | Whether descriptions will be included in the output XML. |
DelimiterComponent Property (EDISDK_EDIFACTTranslator Class)
The character used to separate the classes in a composite element.
Object Oriented Interface
public function getDelimiterComponent(); public function setDelimiterComponent($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 1 ); edisdk_edifacttranslator_set($res, 1, $value );
Default Value
':'
Remarks
The character used to separate the components in a composite element.
This property is not available at design time.
Data Type
String
DelimiterDecimal Property (EDISDK_EDIFACTTranslator Class)
The character used to separate the integer portion of a numeric value from the fractional portion.
Object Oriented Interface
public function getDelimiterDecimal(); public function setDelimiterDecimal($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 2 ); edisdk_edifacttranslator_set($res, 2, $value );
Default Value
'.'
Remarks
The character used to separate the integer portion of a numeric value from the fractional portion.
This property is not available at design time.
Data Type
String
DelimiterElement Property (EDISDK_EDIFACTTranslator Class)
The delimiter used to separate elements within a segment.
Object Oriented Interface
public function getDelimiterElement(); public function setDelimiterElement($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 3 ); edisdk_edifacttranslator_set($res, 3, $value );
Default Value
'+'
Remarks
The delimiter used to separate elements within a segment.
This property is not available at design time.
Data Type
String
DelimiterRelease Property (EDISDK_EDIFACTTranslator Class)
The character used to escape other characters within a property.
Object Oriented Interface
public function getDelimiterRelease(); public function setDelimiterRelease($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 4 ); edisdk_edifacttranslator_set($res, 4, $value );
Default Value
'?'
Remarks
The character used to escape other characters within a field. For example, with the default EDIFACT delimiters, "?+" should be considered "+" character that appears within a field, not an element separator.
This property is not available at design time.
Data Type
String
DelimiterRepetition Property (EDISDK_EDIFACTTranslator Class)
The character used to indicate a repeating element or class.
Object Oriented Interface
public function getDelimiterRepetition(); public function setDelimiterRepetition($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 5 ); edisdk_edifacttranslator_set($res, 5, $value );
Default Value
'*(syntax 4) or empty(syntax 3)'
Remarks
The character used to indicate a repeating element or component.
This property is not available at design time.
Data Type
String
DelimiterSegment Property (EDISDK_EDIFACTTranslator Class)
The character used to terminate a segment.
Object Oriented Interface
public function getDelimiterSegment(); public function setDelimiterSegment($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 6 ); edisdk_edifacttranslator_set($res, 6, $value );
Default Value
'''
Remarks
The character used to terminate a segment.
This property is not available at design time.
Data Type
String
FileWriteMode Property (EDISDK_EDIFACTTranslator Class)
Determines how the output file is opened for writing.
Object Oriented Interface
public function getFileWriteMode(); public function setFileWriteMode($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 7 ); edisdk_edifacttranslator_set($res, 7, $value );
Possible Values
EDIFACTTRANSLATOR_FILEWRITEMODE_CREATE(0),
EDIFACTTRANSLATOR_FILEWRITEMODE_OVERWRITE(1),
EDIFACTTRANSLATOR_FILEWRITEMODE_APPEND(2)
Default Value
0
Remarks
When OutputFile is set, this property determines how the file will be opened.
| fwmCreate (Default) | Creates a new file. If the file already exists, the translation will fail. |
| fwmOverwrite | Opens an existing file and overwrites its contents. If the file does not exist, a new file will be created. |
| fwmAppend | Opens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created. |
This property is not available at design time.
Data Type
Integer
InputData Property (EDISDK_EDIFACTTranslator Class)
The EDI message, specified as a string.
Object Oriented Interface
public function getInputData(); public function setInputData($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 8 ); edisdk_edifacttranslator_set($res, 8, $value );
Default Value
''
Remarks
Set this property to specify the input EDI message as a string. The message can then be parsed with Parse.
This property is not available at design time.
Data Type
String
InputFile Property (EDISDK_EDIFACTTranslator Class)
The file containing the EDI message.
Object Oriented Interface
public function getInputFile(); public function setInputFile($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 9 ); edisdk_edifacttranslator_set($res, 9, $value );
Default Value
''
Remarks
Set this property to specify a file to read the input EDI message from. The message can then be parsed with Parse.
This property is not available at design time.
Data Type
String
InputFormat Property (EDISDK_EDIFACTTranslator Class)
The format of the input data.
Object Oriented Interface
public function getInputFormat(); public function setInputFormat($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 10 ); edisdk_edifacttranslator_set($res, 10, $value );
Possible Values
EDIFACTTRANSLATOR_INPUTFORMAT_EDI(0),
EDIFACTTRANSLATOR_INPUTFORMAT_XML(1)
Default Value
0
Remarks
The value set here, along with OutputFormat, determines how the data is converted when Translate is called.
Possible values are:
- 0 (ifEDI)
- 1 (ifXML)
This property is not available at design time.
Data Type
Integer
OutputData Property (EDISDK_EDIFACTTranslator Class)
The translated EDI data.
Object Oriented Interface
public function getOutputData(); public function setOutputData($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 11 ); edisdk_edifacttranslator_set($res, 11, $value );
Default Value
''
Remarks
This property will be populated with the translated data after calling Translate if OutputFile and SetOutputStream are not set.
This property is not available at design time.
Data Type
String
OutputFile Property (EDISDK_EDIFACTTranslator Class)
The name of the file to write the translated EDI data to.
Object Oriented Interface
public function getOutputFile(); public function setOutputFile($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 12 ); edisdk_edifacttranslator_set($res, 12, $value );
Default Value
''
Remarks
This file specified by this property will be populated with the output after calling Translate if SetOutputStream is not set.
If a file with the specified name already exists Translate will fail unless FileWriteMode is set to "fwmOverwrite" or "fwmAppend".
This property is not available at design time.
Data Type
String
OutputFormat Property (EDISDK_EDIFACTTranslator Class)
The format of the output data.
Object Oriented Interface
public function getOutputFormat(); public function setOutputFormat($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 13 ); edisdk_edifacttranslator_set($res, 13, $value );
Possible Values
EDIFACTTRANSLATOR_OUTPUTFORMAT_EDI(0),
EDIFACTTRANSLATOR_OUTPUTFORMAT_XML(1)
Default Value
0
Remarks
The value set here, along with InputFormat, determines how the data is converted when Translate is called.
Possible values are:
- 0 (ofEDI)
- 1 (ofXML)
This property is not available at design time.
Data Type
Integer
SegmentSuffix Property (EDISDK_EDIFACTTranslator Class)
The suffix that is appended to the end of a segment.
Object Oriented Interface
public function getSegmentSuffix(); public function setSegmentSuffix($value);
Procedural Interface
edisdk_edifacttranslator_get($res, 14 ); edisdk_edifacttranslator_set($res, 14, $value );
Possible Values
EDIFACTTRANSLATOR_SEGMENTSUFFIX_NONE(0),
EDIFACTTRANSLATOR_SEGMENTSUFFIX_CR(1),
EDIFACTTRANSLATOR_SEGMENTSUFFIX_LF(2),
EDIFACTTRANSLATOR_SEGMENTSUFFIX_CRLF(3)
Default Value
3
Remarks
This property determines the suffix that is appended to the end of a segment.
Possible values are:
| ssNone (0) | No suffix is appended to the segment. |
| ssCR (1) | A carriage return (ASCII 13) is appended to the segment. |
| ssLF (2) | A line feed (ASCII 10) is appended to the segment. |
| ssCRLF (3) | A carriage return followed by a line feed (ASCII 13 and 10) is appended to the segment. This is the default value. |
This property is not available at design time.
Data Type
Integer
Config Method (EDISDK_EDIFACTTranslator Class)
Sets or retrieves a configuration setting.
Object Oriented Interface
public function doConfig($configurationstring);
Procedural Interface
edisdk_edifacttranslator_do_config($res, $configurationstring);
Remarks
Config is a generic method available in every class. It is used to set and retrieve configuration settings for the class.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, 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.
LoadSchema Method (EDISDK_EDIFACTTranslator Class)
Loads schema information from a file or string data.
Object Oriented Interface
public function doLoadSchema($fileordata, $messagename);
Procedural Interface
edisdk_edifacttranslator_do_loadschema($res, $fileordata, $messagename);
Remarks
This method loads schema information for use when parsing, validating, and translating messages.
The FileOrData parameter can be set to the path of a file containing schema data, or can be set to the contents of a schema file directly.
MessageName can be set to the name of a specific message to load only the specified message's schema information. If left empty or set to "*", the entire schema will be loaded.
Reset Method (EDISDK_EDIFACTTranslator Class)
Resets all properties to their default values.
Object Oriented Interface
public function doReset();
Procedural Interface
edisdk_edifacttranslator_do_reset($res);
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
Translate Method (EDISDK_EDIFACTTranslator Class)
Translates the specified data.
Object Oriented Interface
public function doTranslate();
Procedural Interface
edisdk_edifacttranslator_do_translate($res);
Remarks
This method translates the specified data.
Error Event (EDISDK_EDIFACTTranslator Class)
Fires when an error occurs during message processing. Normally, the class fails with an error.
Object Oriented Interface
public function fireError($param);
Procedural Interface
edisdk_edifacttranslator_register_callback($res, 1, array($this, 'fireError'));
Parameter List
'errorcode'
'description'
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally, the class fails with an error.
ConnectionId is the associated client Id, 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.
ResolveSchema Event (EDISDK_EDIFACTTranslator Class)
Fires whenever a new EDIFACT message is encountered and no schema is found for it.
Object Oriented Interface
public function fireResolveSchema($param);
Procedural Interface
edisdk_edifacttranslator_register_callback($res, 2, array($this, 'fireResolveSchema'));
Parameter List
'messageversion'
'messagetype'
Remarks
This method fires when the class encounters an EDIFACT message it has not loaded a schema for. The parameters of the event can be used to locate the correct schema and load it with LoadSchema.
MessageVersion - The EDIFACT version of the message, such as D97A.
MessageType - The type of message, such as INVOIC.
After the event fires, if the class still doesn't have a matching schema, then it will attempt schema-less parsing of the EDIFACT message.
ValidateWarning Event (EDISDK_EDIFACTTranslator Class)
Fires to warn about validation errors.
Object Oriented Interface
public function fireValidateWarning($param);
Procedural Interface
edisdk_edifacttranslator_register_callback($res, 3, array($this, 'fireValidateWarning'));
Parameter List
'position'
'line'
'column'
'errorcode'
'errormessage'
'errortype'
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
Config Settings (EDIFACTTranslator Class)
The class 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 class, access to these internal properties is provided through the Config method.EDIFACTTranslator Config Settings
Trappable Errors (EDIFACTTranslator Class)
EDIFACTTranslator Errors
| 202 | Invalid argument. |
| 304 | Cannot write to file. |
| 1003 | Could not find the selected schema in the chosen file. |
| 1099 | Encountered an unexpected segment tag. |
| 1100 | Attempted to perform an action while the component was busy, or close an incomplete interchange. |
| 1044 | Tried to load an invalid schema file. |
| 1203 | Encountered an error while validating the UNA segment. |