X12Translator Module

Properties   Methods   Events   Config Settings   Errors  

The X12Translator module converts X12 documents to XML and back, streamlining translation between formats.

Syntax

EDISDK.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 module with short descriptions. Click on the links for further details.

DelimitersContains the delimiters for the EDI Document.
FileWriteModeDetermines how the output file is opened for writing.
InputDataThe EDI message, specified as a string.
InputFileThe file containing the EDI message.
InputFormatThe format of the input data.
OutputDataThe translated EDI data.
OutputFileThe name of the file to write the translated EDI data to.
OutputFormatThe format of the output data.
SegmentSuffixThe suffix that is appended to the end of a segment.

Method List


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

ConfigSets or retrieves a configuration setting.
LoadSchemaLoads schema information from a file or string data.
ResetResets all properties to their default values.
TranslateTranslates the specified data.

Event List


The following is the full list of the events fired by the module with short descriptions. Click on the links for further details.

ErrorFires when a parsing error occurs.
ResolveSchemaFires to request schema information for a specific transaction set.
ValidateWarningFires to warn about validation errors.

Config Settings


The following is a list of config settings for the module with short descriptions. Click on the links for further details.

CloseStreamAfterTranslateWhether to close the output stream after translation.
EncodingThe character encoding to use for the output X12 document.
UseDescriptionsWhether descriptions will be included in the output XML.

Delimiters Property (X12Translator Module)

Contains the delimiters for the EDI Document.

Syntax

public var delimiters: X12Delimiters {
  get {...}
}

@property (nonatomic,readwrite,assign,getter=delimiterComponent,setter=setDelimiterComponent:) NSString* delimiterComponent;

- (NSString*)delimiterComponent;
- (void)setDelimiterComponent :(NSString*)newDelimiterComponent;

@property (nonatomic,readwrite,assign,getter=delimiterElement,setter=setDelimiterElement:) NSString* delimiterElement;

- (NSString*)delimiterElement;
- (void)setDelimiterElement :(NSString*)newDelimiterElement;

@property (nonatomic,readwrite,assign,getter=delimiterRepetition,setter=setDelimiterRepetition:) NSString* delimiterRepetition;

- (NSString*)delimiterRepetition;
- (void)setDelimiterRepetition :(NSString*)newDelimiterRepetition;

@property (nonatomic,readwrite,assign,getter=delimiterSegment,setter=setDelimiterSegment:) NSString* delimiterSegment;

- (NSString*)delimiterSegment;
- (void)setDelimiterSegment :(NSString*)newDelimiterSegment;

 

Default Value

3

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.

FileWriteMode Property (X12Translator Module)

Determines how the output file is opened for writing.

Syntax

public var fileWriteMode: X12TranslatorFileWriteModes {
  get {...}
  set {...}
}

public enum X12TranslatorFileWriteModes: Int32 { case fwmCreate = 0 case fwmOverwrite = 1 case fwmAppend = 2 }

@property (nonatomic,readwrite,assign,getter=fileWriteMode,setter=setFileWriteMode:) int fileWriteMode;

- (int)fileWriteMode;
- (void)setFileWriteMode :(int)newFileWriteMode;

Default Value

0

Remarks

When OutputFile is set, this property determines how the file will be opened.

fwmCreateCreates a new file. If the file already exists, the translation will fail.
fwmOverwriteOpens an existing file and overwrites its contents. If the file does not exist, a new file will be created.
fwmAppendOpens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created.

InputData Property (X12Translator Module)

The EDI message, specified as a string.

Syntax

public var inputData: String {
  get {...}
  set {...}
}

@property (nonatomic,readwrite,assign,getter=inputData,setter=setInputData:) NSString* inputData;

- (NSString*)inputData;
- (void)setInputData :(NSString*)newInputData;

Default Value

""

Remarks

Set this property to specify the input EDI message as a string. The message can then be parsed with Parse.

InputFile Property (X12Translator Module)

The file containing the EDI message.

Syntax

public var inputFile: String {
  get {...}
  set {...}
}

@property (nonatomic,readwrite,assign,getter=inputFile,setter=setInputFile:) NSString* inputFile;

- (NSString*)inputFile;
- (void)setInputFile :(NSString*)newInputFile;

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.

InputFormat Property (X12Translator Module)

The format of the input data.

Syntax

public var inputFormat: X12TranslatorInputFormats {
  get {...}
  set {...}
}

public enum X12TranslatorInputFormats: Int32 { case ifEDI = 0 case ifXML = 1 }

@property (nonatomic,readwrite,assign,getter=inputFormat,setter=setInputFormat:) int inputFormat;

- (int)inputFormat;
- (void)setInputFormat :(int)newInputFormat;

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)

OutputData Property (X12Translator Module)

The translated EDI data.

Syntax

public var outputData: String {
  get {...}
  set {...}
}

@property (nonatomic,readwrite,assign,getter=outputData,setter=setOutputData:) NSString* outputData;

- (NSString*)outputData;
- (void)setOutputData :(NSString*)newOutputData;

Default Value

""

Remarks

This property will be populated with the translated data after calling Translate if OutputFile and SetOutputStream are not set.

OutputFile Property (X12Translator Module)

The name of the file to write the translated EDI data to.

Syntax

public var outputFile: String {
  get {...}
  set {...}
}

@property (nonatomic,readwrite,assign,getter=outputFile,setter=setOutputFile:) NSString* outputFile;

- (NSString*)outputFile;
- (void)setOutputFile :(NSString*)newOutputFile;

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".

OutputFormat Property (X12Translator Module)

The format of the output data.

Syntax

public var outputFormat: X12TranslatorOutputFormats {
  get {...}
  set {...}
}

public enum X12TranslatorOutputFormats: Int32 { case ofEDI = 0 case ofXML = 1 }

@property (nonatomic,readwrite,assign,getter=outputFormat,setter=setOutputFormat:) int outputFormat;

- (int)outputFormat;
- (void)setOutputFormat :(int)newOutputFormat;

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)

SegmentSuffix Property (X12Translator Module)

The suffix that is appended to the end of a segment.

Syntax

public var segmentSuffix: X12TranslatorSegmentSuffixes {
  get {...}
  set {...}
}

public enum X12TranslatorSegmentSuffixes: Int32 { case ssNone = 0 case ssCR = 1 case ssLF = 2 case ssCRLF = 3 }

@property (nonatomic,readwrite,assign,getter=segmentSuffix,setter=setSegmentSuffix:) int segmentSuffix;

- (int)segmentSuffix;
- (void)setSegmentSuffix :(int)newSegmentSuffix;

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.

Config Method (X12Translator Module)

Sets or retrieves a configuration setting.

Syntax

public func config(configurationString: String) throws -> String
- (NSString*)config:(NSString*)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 (X12Translator Module)

Loads schema information from a file or string data.

Syntax

public func loadSchema(fileOrData: String, messagename: String) throws -> Void
- (void)loadSchema:(NSString*)fileOrData :(NSString*)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 (X12Translator Module)

Resets all properties to their default values.

Syntax

public func reset() throws -> Void
- (void)reset;

Remarks

This method resets all properties of the component to their default values as specified in the property definitions.

Translate Method (X12Translator Module)

Translates the specified data.

Syntax

public func translate() throws -> Void
- (void)translate;

Remarks

This method translates the specified data.

Error Event (X12Translator Module)

Fires when a parsing error occurs.

Syntax

func onError(errorCode: Int32, description: String)
- (void)onError:(int)errorCode :(NSString*)description;

Remarks

This event fires when the class encounters a parsing error while processing a document.

ResolveSchema Event (X12Translator Module)

Fires to request schema information for a specific transaction set.

Syntax

func onResolveSchema(versionNumber: String, transactionSetIDCode: String)
- (void)onResolveSchema:(NSString*)versionNumber :(NSString*)transactionSetIDCode;

Remarks

LoadSchema can be called from within this event to load the schema information for the specified transaction set.

ValidateWarning Event (X12Translator Module)

Fires to warn about validation errors.

Syntax

func onValidateWarning(position: Int64, line: Int32, column: Int32, errorCode: String, errorMessage: String, errorType: Int32)
- (void)onValidateWarning:(long long)position :(int)line :(int)column :(NSString*)errorCode :(NSString*)errorMessage :(int)errorType;

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.

Remarks

This type contains fields specifying the various delimiters used within the X12 document.

The following fields are available:

Fields

component
String

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
String

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
String

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
String

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

public init()

Config Settings (X12Translator Module)

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

CloseStreamAfterTranslate:   Whether to close the output stream after translation.

This setting controls whether the output stream is closed after the translation process is complete. The default value is true.

Encoding:   The character encoding to use for the output X12 document.

This setting specifies the character encoding to be used for the output X12 document. The default value is "UTF-8".

UseDescriptions:   Whether descriptions will be included in the output XML.

This setting controls whether descriptions are included in the output XML. The default value is true.

Trappable Errors (X12Translator Module)

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.