X12Validator Class
Properties Methods Events Config Settings Errors
The X12Validator class validates X12 documents against the specified standard, ensuring compliance and correctness.
Syntax
X12Validator
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.
| Delimiters | Contains the delimiters for the EDI Document. |
| InputData | The EDI message, specified as a string. |
| InputFile | The file containing the EDI message. |
| ValidationErrors | Collection of validation errors for the current document. |
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. |
Delimiters Property (X12Validator Class)
Contains the delimiters for the EDI Document.
Syntax
EDISDKX12Delimiters* GetDelimiters();
char* edisdk_x12validator_getdelimitercomponent(void* lpObj);
int edisdk_x12validator_setdelimitercomponent(void* lpObj, const char* lpszDelimiterComponent);
char* edisdk_x12validator_getdelimiterelement(void* lpObj);
int edisdk_x12validator_setdelimiterelement(void* lpObj, const char* lpszDelimiterElement);
char* edisdk_x12validator_getdelimiterrepetition(void* lpObj);
int edisdk_x12validator_setdelimiterrepetition(void* lpObj, const char* lpszDelimiterRepetition);
char* edisdk_x12validator_getdelimitersegment(void* lpObj);
int edisdk_x12validator_setdelimitersegment(void* lpObj, const char* lpszDelimiterSegment);
QString getDelimiterComponent();
int setDelimiterComponent(QString qsDelimiterComponent); QString getDelimiterElement();
int setDelimiterElement(QString qsDelimiterElement); QString getDelimiterRepetition();
int setDelimiterRepetition(QString qsDelimiterRepetition); QString getDelimiterSegment();
int setDelimiterSegment(QString qsDelimiterSegment);
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.
This property is read-only and not available at design time.
Data Type
InputData Property (X12Validator Class)
The EDI message, specified as a string.
Syntax
ANSI (Cross Platform) char* GetInputData();
int SetInputData(const char* lpszInputData); Unicode (Windows) LPWSTR GetInputData();
INT SetInputData(LPCWSTR lpszInputData);
char* edisdk_x12validator_getinputdata(void* lpObj);
int edisdk_x12validator_setinputdata(void* lpObj, const char* lpszInputData);
QString getInputData();
int setInputData(QString qsInputData);
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 (X12Validator Class)
The file containing the EDI message.
Syntax
ANSI (Cross Platform) char* GetInputFile();
int SetInputFile(const char* lpszInputFile); Unicode (Windows) LPWSTR GetInputFile();
INT SetInputFile(LPCWSTR lpszInputFile);
char* edisdk_x12validator_getinputfile(void* lpObj);
int edisdk_x12validator_setinputfile(void* lpObj, const char* lpszInputFile);
QString getInputFile();
int setInputFile(QString qsInputFile);
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
ValidationErrors Property (X12Validator Class)
Collection of validation errors for the current document.
Syntax
EDISDKList<EDISDKX12ValidationErrorDetail>* GetValidationErrors();
int edisdk_x12validator_getvalidationerrorcount(void* lpObj);
int edisdk_x12validator_getvalidationerrorcolumn(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorcomponentindex(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorelementindex(void* lpObj, int validationerrorindex);
char* edisdk_x12validator_getvalidationerrorerrorcode(void* lpObj, int validationerrorindex);
char* edisdk_x12validator_getvalidationerrorerrormessage(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorerrortype(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorfgroupindex(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorinterchangeindex(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorline(void* lpObj, int validationerrorindex);
int64 edisdk_x12validator_getvalidationerrorposition(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrorsegmentindex(void* lpObj, int validationerrorindex);
char* edisdk_x12validator_getvalidationerrorsegmenttag(void* lpObj, int validationerrorindex);
int edisdk_x12validator_getvalidationerrortransactionsetindex(void* lpObj, int validationerrorindex);
int getValidationErrorCount(); int getValidationErrorColumn(int iValidationErrorIndex); int getValidationErrorComponentIndex(int iValidationErrorIndex); int getValidationErrorElementIndex(int iValidationErrorIndex); QString getValidationErrorErrorCode(int iValidationErrorIndex); QString getValidationErrorErrorMessage(int iValidationErrorIndex); int getValidationErrorErrorType(int iValidationErrorIndex); int getValidationErrorFGroupIndex(int iValidationErrorIndex); int getValidationErrorInterchangeIndex(int iValidationErrorIndex); int getValidationErrorLine(int iValidationErrorIndex); qint64 getValidationErrorPosition(int iValidationErrorIndex); int getValidationErrorSegmentIndex(int iValidationErrorIndex); QString getValidationErrorSegmentTag(int iValidationErrorIndex); int getValidationErrorTransactionSetIndex(int iValidationErrorIndex);
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 and not available at design time.
Data Type
EDISDKX12ValidationErrorDetail
Config Method (X12Validator Class)
Sets or retrieves a configuration setting.
Syntax
ANSI (Cross Platform) char* Config(const char* lpszConfigurationString); Unicode (Windows) LPWSTR Config(LPCWSTR lpszConfigurationString);
char* edisdk_x12validator_config(void* lpObj, const char* lpszConfigurationString);
QString config(const QString& qsConfigurationString);
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.
Error Handling (C++)
This method returns a String value; after it returns, call the GetLastErrorCode() method to obtain its result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
LoadSchema Method (X12Validator Class)
Loads schema information from a file or string data.
Syntax
ANSI (Cross Platform) int LoadSchema(const char* lpszfileOrData, const char* lpszmessagename); Unicode (Windows) INT LoadSchema(LPCWSTR lpszfileOrData, LPCWSTR lpszmessagename);
int edisdk_x12validator_loadschema(void* lpObj, const char* lpszfileOrData, const char* lpszmessagename);
int loadSchema(const QString& qsfileOrData, const QString& qsmessagename);
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.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Reset Method (X12Validator Class)
Resets all properties to their default values.
Syntax
ANSI (Cross Platform) int Reset(); Unicode (Windows) INT Reset();
int edisdk_x12validator_reset(void* lpObj);
int reset();
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Validate Method (X12Validator Class)
Validate the EDI document and warn about any errors encountered.
Syntax
ANSI (Cross Platform) int Validate(); Unicode (Windows) INT Validate();
int edisdk_x12validator_validate(void* lpObj);
int validate();
Remarks
This method parses the input EDI document, firing the ValidateWarning event for any non-blocking errors it encounters.
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)
Error Event (X12Validator Class)
Fires when a parsing error occurs.
Syntax
ANSI (Cross Platform) virtual int FireError(X12ValidatorErrorEventParams *e);
typedef struct {
int ErrorCode;
const char *Description; int reserved; } X12ValidatorErrorEventParams;
Unicode (Windows) virtual INT FireError(X12ValidatorErrorEventParams *e);
typedef struct {
INT ErrorCode;
LPCWSTR Description; INT reserved; } X12ValidatorErrorEventParams;
#define EID_X12VALIDATOR_ERROR 1 virtual INT EDISDK_CALL FireError(INT &iErrorCode, LPSTR &lpszDescription);
class X12ValidatorErrorEventParams {
public:
int errorCode();
const QString &description();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Validator and override this emitter function.
virtual int fireError(X12ValidatorErrorEventParams *e) {...}
// Or, connect one or more slots to this signal.
void error(X12ValidatorErrorEventParams *e);
Remarks
This event fires when the class encounters a parsing error while processing a document.
ResolveSchema Event (X12Validator Class)
Fires to request schema information for a specific transaction set.
Syntax
ANSI (Cross Platform) virtual int FireResolveSchema(X12ValidatorResolveSchemaEventParams *e);
typedef struct {
const char *VersionNumber;
const char *TransactionSetIDCode; int reserved; } X12ValidatorResolveSchemaEventParams;
Unicode (Windows) virtual INT FireResolveSchema(X12ValidatorResolveSchemaEventParams *e);
typedef struct {
LPCWSTR VersionNumber;
LPCWSTR TransactionSetIDCode; INT reserved; } X12ValidatorResolveSchemaEventParams;
#define EID_X12VALIDATOR_RESOLVESCHEMA 2 virtual INT EDISDK_CALL FireResolveSchema(LPSTR &lpszVersionNumber, LPSTR &lpszTransactionSetIDCode);
class X12ValidatorResolveSchemaEventParams {
public:
const QString &versionNumber();
const QString &transactionSetIDCode();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Validator and override this emitter function.
virtual int fireResolveSchema(X12ValidatorResolveSchemaEventParams *e) {...}
// Or, connect one or more slots to this signal.
void resolveSchema(X12ValidatorResolveSchemaEventParams *e);
Remarks
LoadSchema can be called from within this event to load the schema information for the specified transaction set.
ValidateWarning Event (X12Validator Class)
Fires to warn about validation errors.
Syntax
ANSI (Cross Platform) virtual int FireValidateWarning(X12ValidatorValidateWarningEventParams *e);
typedef struct {
int64 Position;
int Line;
int Column;
const char *ErrorCode;
const char *ErrorMessage;
int ErrorType; int reserved; } X12ValidatorValidateWarningEventParams;
Unicode (Windows) virtual INT FireValidateWarning(X12ValidatorValidateWarningEventParams *e);
typedef struct {
LONG64 Position;
INT Line;
INT Column;
LPCWSTR ErrorCode;
LPCWSTR ErrorMessage;
INT ErrorType; INT reserved; } X12ValidatorValidateWarningEventParams;
#define EID_X12VALIDATOR_VALIDATEWARNING 3 virtual INT EDISDK_CALL FireValidateWarning(LONG64 &lPosition, INT &iLine, INT &iColumn, LPSTR &lpszErrorCode, LPSTR &lpszErrorMessage, INT &iErrorType);
class X12ValidatorValidateWarningEventParams {
public:
qint64 position();
int line();
int column();
const QString &errorCode();
const QString &errorMessage();
int errorType();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass X12Validator and override this emitter function.
virtual int fireValidateWarning(X12ValidatorValidateWarningEventParams *e) {...}
// Or, connect one or more slots to this signal.
void validateWarning(X12ValidatorValidateWarningEventParams *e);
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.
Syntax
EDISDKX12Delimiters (declared in edisdk.h)
Remarks
This type contains fields specifying the various delimiters used within the X12 document.
Fields
Component
char*
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
char*
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
char*
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
char*
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
X12Delimiters()
X12ValidationErrorDetail Type
Contains the details of a validation error.
Syntax
EDISDKX12ValidationErrorDetail (declared in edisdk.h)
Remarks
This represents an error that was encountered while validating an X12 document. The fields contain a description of the error and where in the document it occurred.
- Column
- ComponentIndex
- ElementIndex
- ErrorCode
- ErrorMessage
- ErrorType
- FGroupIndex
- InterchangeIndex
- Line
- Position
- SegmentIndex
- SegmentTag
- TransactionSetIndex
Fields
Column
int (read-only)
Default Value: 0
The column number where the error occurred.
ComponentIndex
int (read-only)
Default Value: 1
This field holds the position of the component element where the error occurred.
ElementIndex
int (read-only)
Default Value: 1
This field holds the position of the element where the error occurred.
ErrorCode
char* (read-only)
Default Value: "0"
The ErrorCode field contains the type of error encountered.
ErrorMessage
char* (read-only)
Default Value: ""
ErrorMessage is a textual description of the error.
ErrorType
int (read-only)
Default Value: 0
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 |
FGroupIndex
int (read-only)
Default Value: 1
This field holds the position of the functional group where the error occurred.
InterchangeIndex
int (read-only)
Default Value: 1
This field holds the position of the interchange where the error occurred.
Line
int (read-only)
Default Value: 0
The line number where the error occurred.
Position
int64 (read-only)
Default Value: 0
This field holds the byte position in the EDI stream where the error occurred.
SegmentIndex
int (read-only)
Default Value: 1
This field is the index of the segment where the error occurred.
SegmentTag
char* (read-only)
Default Value: ""
This field specifies the tag name of the segment where the error occurred.
TransactionSetIndex
int (read-only)
Default Value: 1
This field holds the position of the message where the error occurred.
EDISDKList Type
Syntax
EDISDKList<T> (declared in edisdk.h)
Remarks
EDISDKList is a generic class that is used to hold a collection of objects of type T, where T is one of the custom types supported by the X12Validator class.
Methods | |
| GetCount |
This method returns the current size of the collection.
int GetCount() {}
|
| SetCount |
This method sets the size of the collection. This method returns 0 if setting the size was successful; or -1 if the collection is ReadOnly. When adding additional objects to a collection call this method to specify the new size. Increasing the size of the collection preserves existing objects in the collection.
int SetCount(int count) {}
|
| Get |
This method gets the item at the specified position. The index parameter specifies the index of the item in the collection. This method returns NULL if an invalid index is specified.
T* Get(int index) {}
|
| Set |
This method sets the item at the specified position. The index parameter specifies the index of the item in the collection that is being set. This method returns -1 if an invalid index is specified. Note: Objects created using the new operator must be freed using the delete operator; they will not be automatically freed by the class.
T* Set(int index, T* value) {}
|
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)
Error Handling (C++)
Call the GetLastErrorCode() method to obtain the last called method's result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. Known error codes are listed below. If an error occurs, the GetLastError() method can be called to retrieve the associated error message.
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. |