X12Translator Class
Properties Methods Events Config Settings Errors
The X12Translator class converts X12 documents to XML and back, streamlining translation between formats.
Syntax
X12Translator
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.
| Delimiters | Contains the delimiters for the EDI Document. |
| 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 a parsing error occurs. |
| ResolveSchema | Fires to request schema information for a specific transaction set. |
| 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 X12 document. |
| UseDescriptions | Whether descriptions will be included in the output XML. |
Delimiters Property (X12Translator Class)
Contains the delimiters for the EDI Document.
Syntax
EDISDKX12Delimiters* GetDelimiters();
char* edisdk_x12translator_getdelimitercomponent(void* lpObj);
int edisdk_x12translator_setdelimitercomponent(void* lpObj, const char* lpszDelimiterComponent);
char* edisdk_x12translator_getdelimiterelement(void* lpObj);
int edisdk_x12translator_setdelimiterelement(void* lpObj, const char* lpszDelimiterElement);
char* edisdk_x12translator_getdelimiterrepetition(void* lpObj);
int edisdk_x12translator_setdelimiterrepetition(void* lpObj, const char* lpszDelimiterRepetition);
char* edisdk_x12translator_getdelimitersegment(void* lpObj);
int edisdk_x12translator_setdelimitersegment(void* lpObj, const char* lpszDelimiterSegment);
QString getDelimiterComponent();
int setDelimiterComponent(QString qsDelimiterComponent); QString getDelimiterElement();
int setDelimiterElement(QString qsDelimiterElement); QString getDelimiterRepetition();
int setDelimiterRepetition(QString qsDelimiterRepetition); QString getDelimiterSegment();
int setDelimiterSegment(QString qsDelimiterSegment);
Remarks
This property contains the delimiters that will be used when parsing the X12 document. If the document uses delimiters other than the default, change the properties of this object to parse the document correctly.
This property is read-only and not available at design time.
Data Type
FileWriteMode Property (X12Translator Class)
Determines how the output file is opened for writing.
Syntax
ANSI (Cross Platform) int GetFileWriteMode();
int SetFileWriteMode(int iFileWriteMode); Unicode (Windows) INT GetFileWriteMode();
INT SetFileWriteMode(INT iFileWriteMode);
Possible Values
FWM_CREATE(0),
FWM_OVERWRITE(1),
FWM_APPEND(2)
int edisdk_x12translator_getfilewritemode(void* lpObj);
int edisdk_x12translator_setfilewritemode(void* lpObj, int iFileWriteMode);
int getFileWriteMode();
int setFileWriteMode(int iFileWriteMode);
Default Value
0
Remarks
When OutputFile is set, this property determines how the file will be opened.
| fwmCreate | 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 (X12Translator Class)
The EDI message, specified as a string.
Syntax
ANSI (Cross Platform) char* GetInputData();
int SetInputData(const char* lpszInputData); Unicode (Windows) LPWSTR GetInputData();
INT SetInputData(LPCWSTR lpszInputData);
char* edisdk_x12translator_getinputdata(void* lpObj);
int edisdk_x12translator_setinputdata(void* lpObj, const char* lpszInputData);
QString getInputData();
int setInputData(QString qsInputData);
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 (X12Translator Class)
The file containing the EDI message.
Syntax
ANSI (Cross Platform) char* GetInputFile();
int SetInputFile(const char* lpszInputFile); Unicode (Windows) LPWSTR GetInputFile();
INT SetInputFile(LPCWSTR lpszInputFile);
char* edisdk_x12translator_getinputfile(void* lpObj);
int edisdk_x12translator_setinputfile(void* lpObj, const char* lpszInputFile);
QString getInputFile();
int setInputFile(QString qsInputFile);
Default Value
""
Remarks
Set this property to specify the input EDI message as a file. The message can then be parsed with Parse.
If the file is not found or cannot be opened, an error will be returned.
Note: If both InputFile and InputData are set, InputData takes precedence.
This property is not available at design time.
Data Type
String
InputFormat Property (X12Translator Class)
The format of the input data.
Syntax
ANSI (Cross Platform) int GetInputFormat();
int SetInputFormat(int iInputFormat); Unicode (Windows) INT GetInputFormat();
INT SetInputFormat(INT iInputFormat);
Possible Values
IF_EDI(0),
IF_XML(1)
int edisdk_x12translator_getinputformat(void* lpObj);
int edisdk_x12translator_setinputformat(void* lpObj, int iInputFormat);
int getInputFormat();
int setInputFormat(int iInputFormat);
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 (X12Translator Class)
The translated EDI data.
Syntax
ANSI (Cross Platform) char* GetOutputData();
int SetOutputData(const char* lpszOutputData); Unicode (Windows) LPWSTR GetOutputData();
INT SetOutputData(LPCWSTR lpszOutputData);
char* edisdk_x12translator_getoutputdata(void* lpObj);
int edisdk_x12translator_setoutputdata(void* lpObj, const char* lpszOutputData);
QString getOutputData();
int setOutputData(QString qsOutputData);
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 (X12Translator Class)
The name of the file to write the translated EDI data to.
Syntax
ANSI (Cross Platform) char* GetOutputFile();
int SetOutputFile(const char* lpszOutputFile); Unicode (Windows) LPWSTR GetOutputFile();
INT SetOutputFile(LPCWSTR lpszOutputFile);
char* edisdk_x12translator_getoutputfile(void* lpObj);
int edisdk_x12translator_setoutputfile(void* lpObj, const char* lpszOutputFile);
QString getOutputFile();
int setOutputFile(QString qsOutputFile);
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 (X12Translator Class)
The format of the output data.
Syntax
ANSI (Cross Platform) int GetOutputFormat();
int SetOutputFormat(int iOutputFormat); Unicode (Windows) INT GetOutputFormat();
INT SetOutputFormat(INT iOutputFormat);
Possible Values
OF_EDI(0),
OF_XML(1)
int edisdk_x12translator_getoutputformat(void* lpObj);
int edisdk_x12translator_setoutputformat(void* lpObj, int iOutputFormat);
int getOutputFormat();
int setOutputFormat(int iOutputFormat);
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 (X12Translator Class)
The suffix that is appended to the end of a segment.
Syntax
ANSI (Cross Platform) int GetSegmentSuffix();
int SetSegmentSuffix(int iSegmentSuffix); Unicode (Windows) INT GetSegmentSuffix();
INT SetSegmentSuffix(INT iSegmentSuffix);
Possible Values
SS_NONE(0),
SS_CR(1),
SS_LF(2),
SS_CRLF(3)
int edisdk_x12translator_getsegmentsuffix(void* lpObj);
int edisdk_x12translator_setsegmentsuffix(void* lpObj, int iSegmentSuffix);
int getSegmentSuffix();
int setSegmentSuffix(int iSegmentSuffix);
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 (X12Translator Class)
Sets or retrieves a configuration setting.
Syntax
ANSI (Cross Platform) char* Config(const char* lpszConfigurationString); Unicode (Windows) LPWSTR Config(LPCWSTR lpszConfigurationString);
char* edisdk_x12translator_config(void* lpObj, const char* lpszConfigurationString);
QString config(const QString& qsConfigurationString);
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.
Error Handling (C++)
This method returns a String value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
LoadSchema Method (X12Translator Class)
Loads schema information from a file or string data.
Syntax
ANSI (Cross Platform) int LoadSchema(const char* lpszfileOrData, const char* lpszmessagename); Unicode (Windows) INT LoadSchema(LPCWSTR lpszfileOrData, LPCWSTR lpszmessagename);
int edisdk_x12translator_loadschema(void* lpObj, const char* lpszfileOrData, const char* lpszmessagename);
int loadSchema(const QString& qsfileOrData, const QString& qsmessagename);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Reset Method (X12Translator Class)
Resets all properties to their default values.
Syntax
ANSI (Cross Platform) int Reset(); Unicode (Windows) INT Reset();
int edisdk_x12translator_reset(void* lpObj);
int reset();
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Translate Method (X12Translator Class)
Translates the specified data.
Syntax
ANSI (Cross Platform) int Translate(); Unicode (Windows) INT Translate();
int edisdk_x12translator_translate(void* lpObj);
int translate();
Remarks
This method translates the specified data.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Error Event (X12Translator Class)
Fires when a parsing error occurs.
Syntax
ANSI (Cross Platform) virtual int FireError(X12TranslatorErrorEventParams *e);
typedef struct {
int ErrorCode;
const char *Description; int reserved; } X12TranslatorErrorEventParams;
Unicode (Windows) virtual INT FireError(X12TranslatorErrorEventParams *e);
typedef struct {
INT ErrorCode;
LPCWSTR Description; INT reserved; } X12TranslatorErrorEventParams;
#define EID_X12TRANSLATOR_ERROR 1 virtual INT EDISDK_CALL FireError(INT &iErrorCode, LPSTR &lpszDescription);
class X12TranslatorErrorEventParams {
public:
int errorCode();
const QString &description();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Translator and override this emitter function.
virtual int fireError(X12TranslatorErrorEventParams *e) {...}
// Or, connect one or more slots to this signal.
void error(X12TranslatorErrorEventParams *e);
Remarks
This event fires when the class encounters a parsing error while processing a document.
ResolveSchema Event (X12Translator Class)
Fires to request schema information for a specific transaction set.
Syntax
ANSI (Cross Platform) virtual int FireResolveSchema(X12TranslatorResolveSchemaEventParams *e);
typedef struct {
const char *VersionNumber;
const char *TransactionSetIDCode; int reserved; } X12TranslatorResolveSchemaEventParams;
Unicode (Windows) virtual INT FireResolveSchema(X12TranslatorResolveSchemaEventParams *e);
typedef struct {
LPCWSTR VersionNumber;
LPCWSTR TransactionSetIDCode; INT reserved; } X12TranslatorResolveSchemaEventParams;
#define EID_X12TRANSLATOR_RESOLVESCHEMA 2 virtual INT EDISDK_CALL FireResolveSchema(LPSTR &lpszVersionNumber, LPSTR &lpszTransactionSetIDCode);
class X12TranslatorResolveSchemaEventParams {
public:
const QString &versionNumber();
const QString &transactionSetIDCode();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Translator and override this emitter function.
virtual int fireResolveSchema(X12TranslatorResolveSchemaEventParams *e) {...}
// Or, connect one or more slots to this signal.
void resolveSchema(X12TranslatorResolveSchemaEventParams *e);
Remarks
LoadSchema can be called from within this event to load the schema information for the specified transaction set.
ValidateWarning Event (X12Translator Class)
Fires to warn about validation errors.
Syntax
ANSI (Cross Platform) virtual int FireValidateWarning(X12TranslatorValidateWarningEventParams *e);
typedef struct {
int64 Position;
int Line;
int Column;
const char *ErrorCode;
const char *ErrorMessage;
int ErrorType; int reserved; } X12TranslatorValidateWarningEventParams;
Unicode (Windows) virtual INT FireValidateWarning(X12TranslatorValidateWarningEventParams *e);
typedef struct {
LONG64 Position;
INT Line;
INT Column;
LPCWSTR ErrorCode;
LPCWSTR ErrorMessage;
INT ErrorType; INT reserved; } X12TranslatorValidateWarningEventParams;
#define EID_X12TRANSLATOR_VALIDATEWARNING 3 virtual INT EDISDK_CALL FireValidateWarning(LONG64 &lPosition, INT &iLine, INT &iColumn, LPSTR &lpszErrorCode, LPSTR &lpszErrorMessage, INT &iErrorType);
class X12TranslatorValidateWarningEventParams {
public:
qint64 position();
int line();
int column();
const QString &errorCode();
const QString &errorMessage();
int errorType();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Translator and override this emitter function.
virtual int fireValidateWarning(X12TranslatorValidateWarningEventParams *e) {...}
// Or, connect one or more slots to this signal.
void validateWarning(X12TranslatorValidateWarningEventParams *e);
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
X12Delimiters Type
The delimiters used in the X12 document.
Syntax
EDISDKX12Delimiters (declared in edisdk.h)
Remarks
This type contains fields specifying the various delimiters used within the X12 document.
Fields
Component
char*
Default Value: ":"
The delimiter separating components.
In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
Element
char*
Default Value: "*"
The delimiter separating elements.
In X12Reader, this type is used to hold the delimiters found when parsing the element, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
Repetition
char*
Default Value: "^"
The delimiter separating components.
In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
Segment
char*
Default Value: "~"
The delimiter separating segments.
In X12Reader, this type is used to hold the delimiters found when parsing the segment, while in X12Writer the fields can be set to choose the delimiters that will be used when writing
Constructors
X12Delimiters()
Config Settings (X12Translator 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.X12Translator Config Settings
Trappable Errors (X12Translator Class)
Error Handling (C++)
Call the GetLastErrorCode() method to obtain the last called method's result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. Known error codes are listed below. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
X12Translator 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. |