EDIFACTValidator Class
Properties Methods Events Config Settings Errors
The EDIFACTValidator class validates EDIFACT documents against the specified standard, ensuring compliance and correctness.
Syntax
class 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 load_schema 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 validation_errors property will be populated with details of each error.
Inspect the validation_errors 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 class with short descriptions. Click on the links for further details.
| delimiter_component | The character used to separate the classes in a composite element. |
| delimiter_decimal | The character used to separate the integer portion of a numeric value from the fractional portion. |
| delimiter_element | The delimiter used to separate elements within a segment. |
| delimiter_release | The character used to escape other characters within a property. |
| delimiter_repetition | The character used to indicate a repeating element or class. |
| delimiter_segment | The character used to terminate a segment. |
| input_data | The EDI message, specified as a string. |
| input_file | The file containing the EDI message. |
| validation_error_count | The number of records in the ValidationError arrays. |
| validation_error_column | The column number where the error occurred. |
| validation_error_component_index | This property holds the position of the element where the error occurred. |
| validation_error_element_index | This property holds the position of the element where the error occurred. |
| validation_error_error_code | The ErrorCode property contains the type of error encountered. |
| validation_error_error_message | ErrorMessage is a textual description of the error. |
| validation_error_error_type | Indicates the level of the document where the error was encountered. |
| validation_error_f_group_index | This property holds the position of the functional group where the error occurred. |
| validation_error_interchange_index | This property holds the position of the interchange where the error occurred. |
| validation_error_line | The line number where the error occurred. |
| validation_error_message_index | This property holds the position of the message where the error occurred. |
| validation_error_position | This property holds the byte position in the EDI stream where the error occurred. |
| validation_error_segment_index | This property is the index of the segment where the error occurred. |
| validation_error_segment_tag | This property specifies the tag name of the segment where the error occurred. |
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. |
| load_schema | Loads schema information from a file or string data. |
| reset | Resets all properties to their default values. |
| validate | Validate the EDI document and warn about any errors encountered. |
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.
| on_error | Fires when an error occurs during message processing. Normally, the class fails with an error. |
| on_resolve_schema | Fires whenever a new EDIFACT message is encountered and no schema is found for it. |
| on_validate_warning | 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.
| InputFormat | The format of the input EDIFACT document for validation. |
| MaxValidationErrors | The maximum number of validation errors to return. |
delimiter_component property
The character used to separate the classes in a composite element.
Syntax
def get_delimiter_component() -> str: ... def set_delimiter_component(value: str) -> None: ...
delimiter_component = property(get_delimiter_component, set_delimiter_component)
Default Value
":"
Remarks
The character used to separate the components in a composite element.
delimiter_decimal property
The character used to separate the integer portion of a numeric value from the fractional portion.
Syntax
def get_delimiter_decimal() -> str: ... def set_delimiter_decimal(value: str) -> None: ...
delimiter_decimal = property(get_delimiter_decimal, set_delimiter_decimal)
Default Value
"."
Remarks
The character used to separate the integer portion of a numeric value from the fractional portion.
delimiter_element property
The delimiter used to separate elements within a segment.
Syntax
def get_delimiter_element() -> str: ... def set_delimiter_element(value: str) -> None: ...
delimiter_element = property(get_delimiter_element, set_delimiter_element)
Default Value
"+"
Remarks
The delimiter used to separate elements within a segment.
delimiter_release property
The character used to escape other characters within a property.
Syntax
def get_delimiter_release() -> str: ... def set_delimiter_release(value: str) -> None: ...
delimiter_release = property(get_delimiter_release, set_delimiter_release)
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.
delimiter_repetition property
The character used to indicate a repeating element or class.
Syntax
def get_delimiter_repetition() -> str: ... def set_delimiter_repetition(value: str) -> None: ...
delimiter_repetition = property(get_delimiter_repetition, set_delimiter_repetition)
Default Value
"*(syntax 4) or empty(syntax 3)"
Remarks
The character used to indicate a repeating element or component.
delimiter_segment property
The character used to terminate a segment.
Syntax
def get_delimiter_segment() -> str: ... def set_delimiter_segment(value: str) -> None: ...
delimiter_segment = property(get_delimiter_segment, set_delimiter_segment)
Default Value
"'"
Remarks
The character used to terminate a segment.
input_data property
The EDI message, specified as a string.
Syntax
def get_input_data() -> str: ... def set_input_data(value: str) -> None: ...
input_data = property(get_input_data, set_input_data)
Default Value
""
Remarks
Set this property to specify the input EDI message as a string. The message can then be parsed with parse.
input_file property
The file containing the EDI message.
Syntax
def get_input_file() -> str: ... def set_input_file(value: str) -> None: ...
input_file = property(get_input_file, set_input_file)
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.
validation_error_count property
The number of records in the ValidationError arrays.
Syntax
def get_validation_error_count() -> int: ...
validation_error_count = property(get_validation_error_count, None)
Default Value
0
Remarks
This property controls the size of the following arrays:
- validation_error_column
- validation_error_component_index
- validation_error_element_index
- validation_error_error_code
- validation_error_error_message
- validation_error_error_type
- validation_error_f_group_index
- validation_error_interchange_index
- validation_error_line
- validation_error_message_index
- validation_error_position
- validation_error_segment_index
- validation_error_segment_tag
This property is read-only.
validation_error_column property
The column number where the error occurred.
Syntax
def get_validation_error_column(validation_error_index: int) -> int: ...
Default Value
0
Remarks
The column number where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_component_index property
This property holds the position of the element where the error occurred.
Syntax
def get_validation_error_component_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property holds the position of the element where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_element_index property
This property holds the position of the element where the error occurred.
Syntax
def get_validation_error_element_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property holds the position of the element where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_error_code property
The ErrorCode property contains the type of error encountered.
Syntax
def get_validation_error_error_code(validation_error_index: int) -> str: ...
Default Value
"0"
Remarks
The validation_error_error_code property contains the type of error encountered.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_error_message property
ErrorMessage is a textual description of the error.
Syntax
def get_validation_error_error_message(validation_error_index: int) -> str: ...
Default Value
""
Remarks
validation_error_error_message is a textual description of the error.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_error_type property
Indicates the level of the document where the error was encountered.
Syntax
def get_validation_error_error_type(validation_error_index: int) -> int: ...
Default Value
0
Remarks
Indicates the level of the document where the error was encountered. Possible values include:
| 1 | Interchange |
| 2 | Functional group |
| 3 | Message |
| 4 | Segment |
| 5 | Element |
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_f_group_index property
This property holds the position of the functional group where the error occurred.
Syntax
def get_validation_error_f_group_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property holds the position of the functional group where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_interchange_index property
This property holds the position of the interchange where the error occurred.
Syntax
def get_validation_error_interchange_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property holds the position of the interchange where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_line property
The line number where the error occurred.
Syntax
def get_validation_error_line(validation_error_index: int) -> int: ...
Default Value
0
Remarks
The line number where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_message_index property
This property holds the position of the message where the error occurred.
Syntax
def get_validation_error_message_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property holds the position of the message where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_position property
This property holds the byte position in the EDI stream where the error occurred.
Syntax
def get_validation_error_position(validation_error_index: int) -> int: ...
Default Value
0
Remarks
This property holds the byte position in the EDI stream where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_segment_index property
This property is the index of the segment where the error occurred.
Syntax
def get_validation_error_segment_index(validation_error_index: int) -> int: ...
Default Value
1
Remarks
This property is the index of the segment where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
validation_error_segment_tag property
This property specifies the tag name of the segment where the error occurred.
Syntax
def get_validation_error_segment_tag(validation_error_index: int) -> str: ...
Default Value
""
Remarks
This property specifies the tag name of the segment where the error occurred.
The validation_error_index parameter specifies the index of the item in the array. The size of the array is controlled by the validation_error_count property.
This property is read-only.
config method
Sets or retrieves a configuration setting.
Syntax
def config(configuration_string: str) -> str: ...
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.
load_schema method
Loads schema information from a file or string data.
Syntax
def load_schema(file_or_data: str, message_name: str) -> None: ...
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
Resets all properties to their default values.
Syntax
def reset() -> None: ...
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
validate method
Validate the EDI document and warn about any errors encountered.
Syntax
def validate() -> None: ...
Remarks
This method parses the input EDI document, firing the on_validate_warning event for any non-blocking errors it encounters.
on_error event
Fires when an error occurs during message processing. Normally, the class fails with an error.
Syntax
class EDIFACTValidatorErrorEventParams(object): @property def error_code() -> int: ... @property def description() -> str: ... # In class EDIFACTValidator: @property def on_error() -> Callable[[EDIFACTValidatorErrorEventParams], None]: ... @on_error.setter def on_error(event_hook: Callable[[EDIFACTValidatorErrorEventParams], None]) -> None: ...
Remarks
The on_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.
on_resolve_schema event
Fires whenever a new EDIFACT message is encountered and no schema is found for it.
Syntax
class EDIFACTValidatorResolveSchemaEventParams(object): @property def message_version() -> str: ... @property def message_type() -> str: ... # In class EDIFACTValidator: @property def on_resolve_schema() -> Callable[[EDIFACTValidatorResolveSchemaEventParams], None]: ... @on_resolve_schema.setter def on_resolve_schema(event_hook: Callable[[EDIFACTValidatorResolveSchemaEventParams], None]) -> None: ...
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 load_schema.
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.
on_validate_warning event
Fires to warn about validation errors.
Syntax
class EDIFACTValidatorValidateWarningEventParams(object): @property def position() -> int: ... @property def line() -> int: ... @property def column() -> int: ... @property def error_code() -> str: ... @property def error_message() -> str: ... @property def error_type() -> int: ... # In class EDIFACTValidator: @property def on_validate_warning() -> Callable[[EDIFACTValidatorValidateWarningEventParams], None]: ... @on_validate_warning.setter def on_validate_warning(event_hook: Callable[[EDIFACTValidatorValidateWarningEventParams], None]) -> None: ...
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
EDIFACTValidator Config Settings
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 | Meaning |
| 0 (default) | EDIFACT |
| 1 | XML |
EDIFACTValidator Errors
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. |