X12Validator Class
Properties Methods Events Config Settings Errors
The X12Validator class validates X12 documents against the specified standard, ensuring compliance and correctness.
Syntax
class edisdk.X12Validator
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:\X12_Files\810_InvalidRepeat.txt";
validator.LoadSchema(@"C:\X12_Schemas\4010.xml", "810");
validator.Validate();
foreach (X12ValidationErrorDetail 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 delimiter separating classes. |
| delimiter_element | The delimiter separating elements. |
| delimiter_repetition | The delimiter separating classes. |
| delimiter_segment | The delimiter separating segments. |
| 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 class 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_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. |
| validation_error_transaction_set_index | This property holds the position of the message 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 a parsing error occurs. |
| on_resolve_schema | Fires to request schema information for a specific transaction set. |
| 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 X12 document for validation. |
| MaxValidationErrors | The maximum number of validation errors to return. |
delimiter_component property
The delimiter separating classes.
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 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
delimiter_element property
The delimiter separating elements.
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 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
delimiter_repetition property
The delimiter separating classes.
Syntax
def get_delimiter_repetition() -> str: ... def set_delimiter_repetition(value: str) -> None: ...
delimiter_repetition = property(get_delimiter_repetition, set_delimiter_repetition)
Default Value
"^"
Remarks
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
delimiter_segment property
The delimiter separating segments.
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 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
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 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 input_file and input_data are set, input_data takes precedence.
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_position
- validation_error_segment_index
- validation_error_segment_tag
- validation_error_transaction_set_index
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 class 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 component 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 | Transaction set |
| 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_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.
validation_error_transaction_set_index property
This property holds the position of the message where the error occurred.
Syntax
def get_validation_error_transaction_set_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.
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, messagename: 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 a parsing error occurs.
Syntax
class X12ValidatorErrorEventParams(object): @property def error_code() -> int: ... @property def description() -> str: ... # In class X12Validator: @property def on_error() -> Callable[[X12ValidatorErrorEventParams], None]: ... @on_error.setter def on_error(event_hook: Callable[[X12ValidatorErrorEventParams], None]) -> None: ...
Remarks
This event fires when the class encounters a parsing error while processing a document.
on_resolve_schema event
Fires to request schema information for a specific transaction set.
Syntax
class X12ValidatorResolveSchemaEventParams(object): @property def version_number() -> str: ... @property def transaction_set_id_code() -> str: ... # In class X12Validator: @property def on_resolve_schema() -> Callable[[X12ValidatorResolveSchemaEventParams], None]: ... @on_resolve_schema.setter def on_resolve_schema(event_hook: Callable[[X12ValidatorResolveSchemaEventParams], None]) -> None: ...
Remarks
load_schema can be called from within this event to load the schema information for the specified transaction set.
on_validate_warning event
Fires to warn about validation errors.
Syntax
class X12ValidatorValidateWarningEventParams(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 X12Validator: @property def on_validate_warning() -> Callable[[X12ValidatorValidateWarningEventParams], None]: ... @on_validate_warning.setter def on_validate_warning(event_hook: Callable[[X12ValidatorValidateWarningEventParams], None]) -> None: ...
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
X12Validator 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.X12Validator Config Settings
| InputFormat | Meaning |
| 0 (default) | X12 |
| 1 | XML |
X12Validator Errors
X12Validator 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. |