EDIFACTValidator Module

Properties   Methods   Events   Config Settings   Errors  

The EDIFACTValidator module validates EDIFACT documents against the specified standard, ensuring compliance and correctness.

Syntax

EDISDK.EDIFACTValidator

Remarks

This component provides a simple way to validate an EDI document and obtain details about any validation errors.

Before calling Validate call LoadSchema to load the schema for the document to be validated. The schema defines many validation rules such as minimum and maximum lengths, minimum and maximum occurrences, and more. The validation performed by the class depends largely on the schema's definition.

When the Validate method is called the class will attempt to validate the document. If errors are found during validation the ValidationErrors property will be populated with details of each error.

Inspect the ValidationErrors property for information on any errors that were encountered.

Validation Example validator.InputFile = @"C:\EDIFACT_Files\INVOIC_InvalidRepeat.edi"; validator.LoadSchema(@"C:\EDIFACT_Schemas\D97A.xml", "INVOIC"); validator.Validate(); foreach (EDIFACTValidationErrorDetail error in validator.ValidationErrors) { Console.WriteLine(error.ErrorCode + ": " + error.ErrorMessage); }

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.
InputDataThe EDI message, specified as a string.
InputFileThe file containing the EDI message.
ValidationErrorsCollection of validation errors for the current document.

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.
ValidateValidate the EDI document and warn about any errors encountered.

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 an error occurs during message processing. Normally, the module fails with an error.
ResolveSchemaFires whenever a new EDIFACT message is encountered and no schema is found for it.
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.

InputFormatThe format of the input EDIFACT document for validation.
MaxValidationErrorsThe maximum number of validation errors to return.

Delimiters Property (EDIFACTValidator Module)

Contains the delimiters for the EDI Document.

Syntax

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

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

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

@property (nonatomic,readwrite,assign,getter=delimiterDecimal,setter=setDelimiterDecimal:) NSString* delimiterDecimal;

- (NSString*)delimiterDecimal;
- (void)setDelimiterDecimal :(NSString*)newDelimiterDecimal;

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

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

@property (nonatomic,readwrite,assign,getter=delimiterRelease,setter=setDelimiterRelease:) NSString* delimiterRelease;

- (NSString*)delimiterRelease;
- (void)setDelimiterRelease :(NSString*)newDelimiterRelease;

@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

""

Remarks

This property contains the delimiters that will be used when parsing the EDIFACT 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.

InputData Property (EDIFACTValidator 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 (EDIFACTValidator 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 a file to read the input EDI message from. The message can then be parsed with Parse.

ValidationErrors Property (EDIFACTValidator Module)

Collection of validation errors for the current document.

Syntax

public var validationErrors: Array<EDIFACTValidationErrorDetail> {
  get {...}
}

@property (nonatomic,readonly,assign,getter=validationErrorCount) int validationErrorCount;

- (int)validationErrorCount;

- (int)validationErrorColumn:(int)validationErrorIndex;

- (int)validationErrorComponentIndex:(int)validationErrorIndex;

- (int)validationErrorElementIndex:(int)validationErrorIndex;

- (NSString*)validationErrorErrorCode:(int)validationErrorIndex;

- (NSString*)validationErrorErrorMessage:(int)validationErrorIndex;

- (int)validationErrorErrorType:(int)validationErrorIndex;

- (int)validationErrorFGroupIndex:(int)validationErrorIndex;

- (int)validationErrorInterchangeIndex:(int)validationErrorIndex;

- (int)validationErrorLine:(int)validationErrorIndex;

- (int)validationErrorMessageIndex:(int)validationErrorIndex;

- (long long)validationErrorPosition:(int)validationErrorIndex;

- (int)validationErrorSegmentIndex:(int)validationErrorIndex;

- (NSString*)validationErrorSegmentTag:(int)validationErrorIndex;

Default Value

""

Remarks

After calling Validate this property contains details of any validation errors. Validation errors are also accessible through the ValidateWarning event as the document is validated.

This property is read-only.

Config Method (EDIFACTValidator 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 (EDIFACTValidator 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 (EDIFACTValidator 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.

Validate Method (EDIFACTValidator Module)

Validate the EDI document and warn about any errors encountered.

Syntax

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

Remarks

This method parses the input EDI document, firing the ValidateWarning event for any non-blocking errors it encounters.

Error Event (EDIFACTValidator Module)

Fires when an error occurs during message processing. Normally, the component fails with an error.

Syntax

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

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally, the class .

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 (EDIFACTValidator Module)

Fires whenever a new EDIFACT message is encountered and no schema is found for it.

Syntax

func onResolveSchema(messageVersion: String, messageType: String)
- (void)onResolveSchema:(NSString*)messageVersion :(NSString*)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 (EDIFACTValidator 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.

EDIFACTDelimiters Type

The delimiters used in the EDIFACT document.

Remarks

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

The following fields are available:

Fields

component
String

Default Value: ":"

The character used to separate the components in a composite element.

decimal
String

Default Value: "."

The character used to separate the integer portion of a numeric value from the fractional portion.

element
String

Default Value: "+"

The delimiter used to separate elements within a segment.

release
String

Default Value: "?"

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.

repetition
String

Default Value: "*(syntax 4) or empty(syntax 3)"

The character used to indicate a repeating element or component.

segment
String

Default Value: "'"

The character used to terminate a segment.

Constructors

public init()

EDIFACTValidationErrorDetail Type

Contains the details of a validation error.

Remarks

This represents an error that was encountered while validating an EDIFACT document. The fields contain a description of the error and where in the document it occurred.

The following fields are available:

Fields

column
Int32 (read-only)

Default Value: 0

The column number where the error occurred.

componentIndex
Int32 (read-only)

Default Value: 1

This property holds the position of the element where the error occurred.

elementIndex
Int32 (read-only)

Default Value: 1

This property holds the position of the element where the error occurred.

errorCode
String (read-only)

Default Value: "0"

The property contains the type of error encountered.

errorMessage
String (read-only)

Default Value: ""

is a textual description of the error.

errorType
Int32 (read-only)

Default Value: 0

Indicates the level of the document where the error was encountered. Possible values include:

1Interchange
2Functional group
3Message
4Segment
5Element

fGroupIndex
Int32 (read-only)

Default Value: 1

This property holds the position of the functional group where the error occurred.

interchangeIndex
Int32 (read-only)

Default Value: 1

This property holds the position of the interchange where the error occurred.

line
Int32 (read-only)

Default Value: 0

The line number where the error occurred.

messageIndex
Int32 (read-only)

Default Value: 1

This property holds the position of the message where the error occurred.

position
Int64 (read-only)

Default Value: 0

This property holds the byte position in the EDI stream where the error occurred.

segmentIndex
Int32 (read-only)

Default Value: 1

This property is the index of the segment where the error occurred.

segmentTag
String (read-only)

Default Value: ""

This property specifies the tag name of the segment where the error occurred.

Config Settings (EDIFACTValidator 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.

EDIFACTValidator Config Settings

InputFormat:   The format of the input EDIFACT document for validation.

This setting controls the type of input EDIFACT document for validation. Possible values are:

InputFormatMeaning
0 (default)EDIFACT
1XML
MaxValidationErrors:   The maximum number of validation errors to return.

This setting controls the maximum number of validation errors that will be returned during the validation process. The default value is 200.

Trappable Errors (EDIFACTValidator Module)

EDIFACTValidator 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.
1201   The index is out of range.
1202   The selected ACK type is invalid.
1203   Encountered an error while validating the UNA segment.