EDIFACTValidator Class
Properties Methods Events Config Settings Errors
The EDIFACTValidator class validates EDIFACT documents against the specified standard, ensuring compliance and correctness.
Syntax
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 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 an error occurs during message processing. Normally, the class fails with an error. |
| ResolveSchema | Fires whenever a new EDIFACT message is encountered and no schema is found for it. |
| 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 EDIFACT document for validation. |
| MaxValidationErrors | The maximum number of validation errors to return. |
Delimiters Property (EDIFACTValidator Class)
Contains the delimiters for the EDI Document.
Syntax
EDISDKEDIFACTDelimiters* GetDelimiters();
char* edisdk_edifactvalidator_getdelimitercomponent(void* lpObj);
int edisdk_edifactvalidator_setdelimitercomponent(void* lpObj, const char* lpszDelimiterComponent);
char* edisdk_edifactvalidator_getdelimiterdecimal(void* lpObj);
int edisdk_edifactvalidator_setdelimiterdecimal(void* lpObj, const char* lpszDelimiterDecimal);
char* edisdk_edifactvalidator_getdelimiterelement(void* lpObj);
int edisdk_edifactvalidator_setdelimiterelement(void* lpObj, const char* lpszDelimiterElement);
char* edisdk_edifactvalidator_getdelimiterrelease(void* lpObj);
int edisdk_edifactvalidator_setdelimiterrelease(void* lpObj, const char* lpszDelimiterRelease);
char* edisdk_edifactvalidator_getdelimiterrepetition(void* lpObj);
int edisdk_edifactvalidator_setdelimiterrepetition(void* lpObj, const char* lpszDelimiterRepetition);
char* edisdk_edifactvalidator_getdelimitersegment(void* lpObj);
int edisdk_edifactvalidator_setdelimitersegment(void* lpObj, const char* lpszDelimiterSegment);
QString getDelimiterComponent();
int setDelimiterComponent(QString qsDelimiterComponent); QString getDelimiterDecimal();
int setDelimiterDecimal(QString qsDelimiterDecimal); QString getDelimiterElement();
int setDelimiterElement(QString qsDelimiterElement); QString getDelimiterRelease();
int setDelimiterRelease(QString qsDelimiterRelease); 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 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 and not available at design time.
Data Type
InputData Property (EDIFACTValidator 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_edifactvalidator_getinputdata(void* lpObj);
int edisdk_edifactvalidator_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 (EDIFACTValidator 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_edifactvalidator_getinputfile(void* lpObj);
int edisdk_edifactvalidator_setinputfile(void* lpObj, const char* lpszInputFile);
QString getInputFile();
int setInputFile(QString qsInputFile);
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.
This property is not available at design time.
Data Type
String
ValidationErrors Property (EDIFACTValidator Class)
Collection of validation errors for the current document.
Syntax
EDISDKList<EDISDKEDIFACTValidationErrorDetail>* GetValidationErrors();
int edisdk_edifactvalidator_getvalidationerrorcount(void* lpObj);
int edisdk_edifactvalidator_getvalidationerrorcolumn(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorcomponentindex(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorelementindex(void* lpObj, int validationerrorindex);
char* edisdk_edifactvalidator_getvalidationerrorerrorcode(void* lpObj, int validationerrorindex);
char* edisdk_edifactvalidator_getvalidationerrorerrormessage(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorerrortype(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorfgroupindex(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorinterchangeindex(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorline(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrormessageindex(void* lpObj, int validationerrorindex);
int64 edisdk_edifactvalidator_getvalidationerrorposition(void* lpObj, int validationerrorindex);
int edisdk_edifactvalidator_getvalidationerrorsegmentindex(void* lpObj, int validationerrorindex);
char* edisdk_edifactvalidator_getvalidationerrorsegmenttag(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); int getValidationErrorMessageIndex(int iValidationErrorIndex); qint64 getValidationErrorPosition(int iValidationErrorIndex); int getValidationErrorSegmentIndex(int iValidationErrorIndex); QString getValidationErrorSegmentTag(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
EDISDKEDIFACTValidationErrorDetail
Config Method (EDIFACTValidator Class)
Sets or retrieves a configuration setting.
Syntax
ANSI (Cross Platform) char* Config(const char* lpszConfigurationString); Unicode (Windows) LPWSTR Config(LPCWSTR lpszConfigurationString);
char* edisdk_edifactvalidator_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 (EDIFACTValidator 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_edifactvalidator_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 (EDIFACTValidator Class)
Resets all properties to their default values.
Syntax
ANSI (Cross Platform) int Reset(); Unicode (Windows) INT Reset();
int edisdk_edifactvalidator_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 (EDIFACTValidator Class)
Validate the EDI document and warn about any errors encountered.
Syntax
ANSI (Cross Platform) int Validate(); Unicode (Windows) INT Validate();
int edisdk_edifactvalidator_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 (EDIFACTValidator Class)
Fires when an error occurs during message processing. Normally, the class fails with an error.
Syntax
ANSI (Cross Platform) virtual int FireError(EDIFACTValidatorErrorEventParams *e);
typedef struct {
int ErrorCode;
const char *Description; int reserved; } EDIFACTValidatorErrorEventParams;
Unicode (Windows) virtual INT FireError(EDIFACTValidatorErrorEventParams *e);
typedef struct {
INT ErrorCode;
LPCWSTR Description; INT reserved; } EDIFACTValidatorErrorEventParams;
#define EID_EDIFACTVALIDATOR_ERROR 1 virtual INT EDISDK_CALL FireError(INT &iErrorCode, LPSTR &lpszDescription);
class EDIFACTValidatorErrorEventParams {
public:
int errorCode();
const QString &description();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass EDIFACTValidator and override this emitter function.
virtual int fireError(EDIFACTValidatorErrorEventParams *e) {...}
// Or, connect one or more slots to this signal.
void error(EDIFACTValidatorErrorEventParams *e);
Remarks
The 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.
ResolveSchema Event (EDIFACTValidator Class)
Fires whenever a new EDIFACT message is encountered and no schema is found for it.
Syntax
ANSI (Cross Platform) virtual int FireResolveSchema(EDIFACTValidatorResolveSchemaEventParams *e);
typedef struct {
const char *MessageVersion;
const char *MessageType; int reserved; } EDIFACTValidatorResolveSchemaEventParams;
Unicode (Windows) virtual INT FireResolveSchema(EDIFACTValidatorResolveSchemaEventParams *e);
typedef struct {
LPCWSTR MessageVersion;
LPCWSTR MessageType; INT reserved; } EDIFACTValidatorResolveSchemaEventParams;
#define EID_EDIFACTVALIDATOR_RESOLVESCHEMA 2 virtual INT EDISDK_CALL FireResolveSchema(LPSTR &lpszMessageVersion, LPSTR &lpszMessageType);
class EDIFACTValidatorResolveSchemaEventParams {
public:
const QString &messageVersion();
const QString &messageType();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass EDIFACTValidator and override this emitter function.
virtual int fireResolveSchema(EDIFACTValidatorResolveSchemaEventParams *e) {...}
// Or, connect one or more slots to this signal.
void resolveSchema(EDIFACTValidatorResolveSchemaEventParams *e);
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 Class)
Fires to warn about validation errors.
Syntax
ANSI (Cross Platform) virtual int FireValidateWarning(EDIFACTValidatorValidateWarningEventParams *e);
typedef struct {
int64 Position;
int Line;
int Column;
const char *ErrorCode;
const char *ErrorMessage;
int ErrorType; int reserved; } EDIFACTValidatorValidateWarningEventParams;
Unicode (Windows) virtual INT FireValidateWarning(EDIFACTValidatorValidateWarningEventParams *e);
typedef struct {
LONG64 Position;
INT Line;
INT Column;
LPCWSTR ErrorCode;
LPCWSTR ErrorMessage;
INT ErrorType; INT reserved; } EDIFACTValidatorValidateWarningEventParams;
#define EID_EDIFACTVALIDATOR_VALIDATEWARNING 3 virtual INT EDISDK_CALL FireValidateWarning(LONG64 &lPosition, INT &iLine, INT &iColumn, LPSTR &lpszErrorCode, LPSTR &lpszErrorMessage, INT &iErrorType);
class EDIFACTValidatorValidateWarningEventParams {
public:
qint64 position();
int line();
int column();
const QString &errorCode();
const QString &errorMessage();
int errorType();
int eventRetVal();
void setEventRetVal(int iRetVal);
};
// To handle, subclass EDIFACTValidator and override this emitter function.
virtual int fireValidateWarning(EDIFACTValidatorValidateWarningEventParams *e) {...}
// Or, connect one or more slots to this signal.
void validateWarning(EDIFACTValidatorValidateWarningEventParams *e);
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.
Syntax
EDISDKEDIFACTDelimiters (declared in edisdk.h)
Remarks
This type contains fields specifying the various delimiters used within the EDIFACT document.
Fields
Component
char*
Default Value: ":"
The character used to separate the components in a composite element.
Decimal
char*
Default Value: "."
The character used to separate the integer portion of a numeric value from the fractional portion.
Element
char*
Default Value: "+"
The delimiter used to separate elements within a segment.
Release
char*
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
char*
Default Value: "*(syntax 4) or empty(syntax 3)"
The character used to indicate a repeating element or component.
Segment
char*
Default Value: "'"
The character used to terminate a segment.
Constructors
EDIFACTDelimiters()
EDIFACTValidationErrorDetail Type
Contains the details of a validation error.
Syntax
EDISDKEDIFACTValidationErrorDetail (declared in edisdk.h)
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.
- Column
- ComponentIndex
- ElementIndex
- ErrorCode
- ErrorMessage
- ErrorType
- FGroupIndex
- InterchangeIndex
- Line
- MessageIndex
- Position
- SegmentIndex
- SegmentTag
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 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 | Message |
| 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.
MessageIndex
int (read-only)
Default Value: 1
This field holds the position of the message 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.
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 EDIFACTValidator 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 (EDIFACTValidator 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.EDIFACTValidator Config Settings
| InputFormat | Meaning |
| 0 (default) | EDIFACT |
| 1 | XML |
Trappable Errors (EDIFACTValidator 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.
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. |