X12Validator Class
Properties Methods Events Config Settings Errors
The X12Validator class validates X12 documents against the specified standard, ensuring compliance and correctness.
Class Name
EDISDK_X12Validator
Procedural Interface
edisdk_x12validator_open(); edisdk_x12validator_close($res); edisdk_x12validator_register_callback($res, $id, $function); edisdk_x12validator_get_last_error($res); edisdk_x12validator_get_last_error_code($res); edisdk_x12validator_set($res, $id, $index, $value); edisdk_x12validator_get($res, $id, $index); edisdk_x12validator_do_config($res, $configurationstring); edisdk_x12validator_do_loadschema($res, $fileordata, $messagename); edisdk_x12validator_do_reset($res); edisdk_x12validator_do_validate($res);
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:\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.
| DelimiterComponent | The delimiter separating classes. |
| DelimiterElement | The delimiter separating elements. |
| DelimiterRepetition | The delimiter separating classes. |
| DelimiterSegment | The delimiter separating segments. |
| InputData | The EDI message, specified as a string. |
| InputFile | The file containing the EDI message. |
| ValidationErrorCount | The number of records in the ValidationError arrays. |
| ValidationErrorColumn | The column number where the error occurred. |
| ValidationErrorComponentIndex | This property holds the position of the class element where the error occurred. |
| ValidationErrorElementIndex | This property holds the position of the element where the error occurred. |
| ValidationErrorErrorCode | The ErrorCode property contains the type of error encountered. |
| ValidationErrorErrorMessage | ErrorMessage is a textual description of the error. |
| ValidationErrorErrorType | Indicates the level of the document where the error was encountered. |
| ValidationErrorFGroupIndex | This property holds the position of the functional group where the error occurred. |
| ValidationErrorInterchangeIndex | This property holds the position of the interchange where the error occurred. |
| ValidationErrorLine | The line number where the error occurred. |
| ValidationErrorPosition | This property holds the byte position in the EDI stream where the error occurred. |
| ValidationErrorSegmentIndex | This property is the index of the segment where the error occurred. |
| ValidationErrorSegmentTag | This property specifies the tag name of the segment where the error occurred. |
| ValidationErrorTransactionSetIndex | 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. |
| LoadSchema | 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.
| 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.
| InputFormat | The format of the input X12 document for validation. |
| MaxValidationErrors | The maximum number of validation errors to return. |
DelimiterComponent Property (EDISDK_X12Validator Class)
The delimiter separating classes.
Object Oriented Interface
public function getDelimiterComponent(); public function setDelimiterComponent($value);
Procedural Interface
edisdk_x12validator_get($res, 1 ); edisdk_x12validator_set($res, 1, $value );
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
This property is not available at design time.
Data Type
String
DelimiterElement Property (EDISDK_X12Validator Class)
The delimiter separating elements.
Object Oriented Interface
public function getDelimiterElement(); public function setDelimiterElement($value);
Procedural Interface
edisdk_x12validator_get($res, 2 ); edisdk_x12validator_set($res, 2, $value );
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
This property is not available at design time.
Data Type
String
DelimiterRepetition Property (EDISDK_X12Validator Class)
The delimiter separating classes.
Object Oriented Interface
public function getDelimiterRepetition(); public function setDelimiterRepetition($value);
Procedural Interface
edisdk_x12validator_get($res, 3 ); edisdk_x12validator_set($res, 3, $value );
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
This property is not available at design time.
Data Type
String
DelimiterSegment Property (EDISDK_X12Validator Class)
The delimiter separating segments.
Object Oriented Interface
public function getDelimiterSegment(); public function setDelimiterSegment($value);
Procedural Interface
edisdk_x12validator_get($res, 4 ); edisdk_x12validator_set($res, 4, $value );
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
This property is not available at design time.
Data Type
String
InputData Property (EDISDK_X12Validator Class)
The EDI message, specified as a string.
Object Oriented Interface
public function getInputData(); public function setInputData($value);
Procedural Interface
edisdk_x12validator_get($res, 5 ); edisdk_x12validator_set($res, 5, $value );
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 (EDISDK_X12Validator Class)
The file containing the EDI message.
Object Oriented Interface
public function getInputFile(); public function setInputFile($value);
Procedural Interface
edisdk_x12validator_get($res, 6 ); edisdk_x12validator_set($res, 6, $value );
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
ValidationErrorCount Property (EDISDK_X12Validator Class)
The number of records in the ValidationError arrays.
Object Oriented Interface
public function getValidationErrorCount();
Procedural Interface
edisdk_x12validator_get($res, 7 );
Default Value
0
Remarks
This property controls the size of the following arrays:
- ValidationErrorColumn
- ValidationErrorComponentIndex
- ValidationErrorElementIndex
- ValidationErrorErrorCode
- ValidationErrorErrorMessage
- ValidationErrorErrorType
- ValidationErrorFGroupIndex
- ValidationErrorInterchangeIndex
- ValidationErrorLine
- ValidationErrorPosition
- ValidationErrorSegmentIndex
- ValidationErrorSegmentTag
- ValidationErrorTransactionSetIndex
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorColumn Property (EDISDK_X12Validator Class)
The column number where the error occurred.
Object Oriented Interface
public function getValidationErrorColumn($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 8 , $validationerrorindex);
Default Value
0
Remarks
The column number where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorComponentIndex Property (EDISDK_X12Validator Class)
This property holds the position of the class element where the error occurred.
Object Oriented Interface
public function getValidationErrorComponentIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 9 , $validationerrorindex);
Default Value
1
Remarks
This property holds the position of the component element where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorElementIndex Property (EDISDK_X12Validator Class)
This property holds the position of the element where the error occurred.
Object Oriented Interface
public function getValidationErrorElementIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 10 , $validationerrorindex);
Default Value
1
Remarks
This property holds the position of the element where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorErrorCode Property (EDISDK_X12Validator Class)
The ErrorCode property contains the type of error encountered.
Object Oriented Interface
public function getValidationErrorErrorCode($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 11 , $validationerrorindex);
Default Value
'0'
Remarks
The ValidationErrorErrorCode property contains the type of error encountered.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
String
ValidationErrorErrorMessage Property (EDISDK_X12Validator Class)
ErrorMessage is a textual description of the error.
Object Oriented Interface
public function getValidationErrorErrorMessage($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 12 , $validationerrorindex);
Default Value
''
Remarks
ValidationErrorErrorMessage is a textual description of the error.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
String
ValidationErrorErrorType Property (EDISDK_X12Validator Class)
Indicates the level of the document where the error was encountered.
Object Oriented Interface
public function getValidationErrorErrorType($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 13 , $validationerrorindex);
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 $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorFGroupIndex Property (EDISDK_X12Validator Class)
This property holds the position of the functional group where the error occurred.
Object Oriented Interface
public function getValidationErrorFGroupIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 14 , $validationerrorindex);
Default Value
1
Remarks
This property holds the position of the functional group where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorInterchangeIndex Property (EDISDK_X12Validator Class)
This property holds the position of the interchange where the error occurred.
Object Oriented Interface
public function getValidationErrorInterchangeIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 15 , $validationerrorindex);
Default Value
1
Remarks
This property holds the position of the interchange where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorLine Property (EDISDK_X12Validator Class)
The line number where the error occurred.
Object Oriented Interface
public function getValidationErrorLine($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 16 , $validationerrorindex);
Default Value
0
Remarks
The line number where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorPosition Property (EDISDK_X12Validator Class)
This property holds the byte position in the EDI stream where the error occurred.
Object Oriented Interface
public function getValidationErrorPosition($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 17 , $validationerrorindex);
Default Value
0
Remarks
This property holds the byte position in the EDI stream where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Long64
ValidationErrorSegmentIndex Property (EDISDK_X12Validator Class)
This property is the index of the segment where the error occurred.
Object Oriented Interface
public function getValidationErrorSegmentIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 18 , $validationerrorindex);
Default Value
1
Remarks
This property is the index of the segment where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
ValidationErrorSegmentTag Property (EDISDK_X12Validator Class)
This property specifies the tag name of the segment where the error occurred.
Object Oriented Interface
public function getValidationErrorSegmentTag($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 19 , $validationerrorindex);
Default Value
''
Remarks
This property specifies the tag name of the segment where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
String
ValidationErrorTransactionSetIndex Property (EDISDK_X12Validator Class)
This property holds the position of the message where the error occurred.
Object Oriented Interface
public function getValidationErrorTransactionSetIndex($validationerrorindex);
Procedural Interface
edisdk_x12validator_get($res, 20 , $validationerrorindex);
Default Value
1
Remarks
This property holds the position of the message where the error occurred.
The $validationerrorindex parameter specifies the index of the item in the array. The size of the array is controlled by the ValidationErrorCount property.
This property is read-only and not available at design time.
Data Type
Integer
Config Method (EDISDK_X12Validator Class)
Sets or retrieves a configuration setting.
Object Oriented Interface
public function doConfig($configurationstring);
Procedural Interface
edisdk_x12validator_do_config($res, $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 (EDISDK_X12Validator Class)
Loads schema information from a file or string data.
Object Oriented Interface
public function doLoadSchema($fileordata, $messagename);
Procedural Interface
edisdk_x12validator_do_loadschema($res, $fileordata, $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 (EDISDK_X12Validator Class)
Resets all properties to their default values.
Object Oriented Interface
public function doReset();
Procedural Interface
edisdk_x12validator_do_reset($res);
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
Validate Method (EDISDK_X12Validator Class)
Validate the EDI document and warn about any errors encountered.
Object Oriented Interface
public function doValidate();
Procedural Interface
edisdk_x12validator_do_validate($res);
Remarks
This method parses the input EDI document, firing the ValidateWarning event for any non-blocking errors it encounters.
Error Event (EDISDK_X12Validator Class)
Fires when a parsing error occurs.
Object Oriented Interface
public function fireError($param);
Procedural Interface
edisdk_x12validator_register_callback($res, 1, array($this, 'fireError'));
Parameter List
'errorcode'
'description'
Remarks
This event fires when the class encounters a parsing error while processing a document.
ResolveSchema Event (EDISDK_X12Validator Class)
Fires to request schema information for a specific transaction set.
Object Oriented Interface
public function fireResolveSchema($param);
Procedural Interface
edisdk_x12validator_register_callback($res, 2, array($this, 'fireResolveSchema'));
Parameter List
'versionnumber'
'transactionsetidcode'
Remarks
LoadSchema can be called from within this event to load the schema information for the specified transaction set.
ValidateWarning Event (EDISDK_X12Validator Class)
Fires to warn about validation errors.
Object Oriented Interface
public function fireValidateWarning($param);
Procedural Interface
edisdk_x12validator_register_callback($res, 3, array($this, 'fireValidateWarning'));
Parameter List
'position'
'line'
'column'
'errorcode'
'errormessage'
'errortype'
Remarks
When the class encounters a non-blocking error while validating a document, this event fires with information about the error.
Config Settings (X12Validator 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.X12Validator Config Settings
| InputFormat | Meaning |
| 0 (default) | X12 |
| 1 | XML |
Trappable Errors (X12Validator Class)
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. |