EDIFACTValidator Component
Properties Methods Events Config Settings Errors
The EDIFACTValidator component validates EDIFACT documents against the specified standard, ensuring compliance and correctness.
Syntax
nsoftware.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 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 component depends largely on the schema's definition.
When the Validate method is called the component 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 component 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 component 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. |
| SetInputStream | The stream containing the EDI data. |
| 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 component with short descriptions. Click on the links for further details.
| Error | Fires when an error occurs during message processing. Normally, the component 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 component 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 Component)
Contains the delimiters for the EDI Document.
Syntax
public EDIFACTDelimiters Delimiters { get; }
Public ReadOnly Property Delimiters As EDIFACTDelimiters
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.
Please refer to the EDIFACTDelimiters type for a complete list of fields.InputData Property (EDIFACTValidator Component)
The EDI message, specified as a string.
Syntax
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.
InputFile Property (EDIFACTValidator Component)
The file containing the EDI message.
Syntax
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.
ValidationErrors Property (EDIFACTValidator Component)
Collection of validation errors for the current document.
Syntax
public EDIFACTValidationErrorDetailList ValidationErrors { get; }
Public ReadOnly Property ValidationErrors As EDIFACTValidationErrorDetailList
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.
Please refer to the EDIFACTValidationErrorDetail type for a complete list of fields.Config Method (EDIFACTValidator Component)
Sets or retrieves a configuration setting.
Syntax
Remarks
Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, 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 (EDIFACTValidator Component)
Loads schema information from a file or string data.
Syntax
public void LoadSchema(string fileOrData, string messageName); Async Version public async Task LoadSchema(string fileOrData, string messageName); public async Task LoadSchema(string fileOrData, string messageName, CancellationToken cancellationToken);
Public Sub LoadSchema(ByVal fileOrData As String, ByVal messageName As String) Async Version Public Sub LoadSchema(ByVal fileOrData As String, ByVal messageName As String) As Task Public Sub LoadSchema(ByVal fileOrData As String, ByVal messageName As String, cancellationToken As CancellationToken) As Task
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 (EDIFACTValidator Component)
Resets all properties to their default values.
Syntax
public void Reset(); Async Version public async Task Reset(); public async Task Reset(CancellationToken cancellationToken);
Public Sub Reset() Async Version Public Sub Reset() As Task Public Sub Reset(cancellationToken As CancellationToken) As Task
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
SetInputStream Method (EDIFACTValidator Component)
The stream containing the EDI data.
Syntax
public void SetInputStream(System.IO.Stream inputStream); Async Version public async Task SetInputStream(System.IO.Stream inputStream); public async Task SetInputStream(System.IO.Stream inputStream, CancellationToken cancellationToken);
Public Sub SetInputStream(ByVal InputStream As System.IO.Stream) Async Version Public Sub SetInputStream(ByVal InputStream As System.IO.Stream) As Task Public Sub SetInputStream(ByVal InputStream As System.IO.Stream, cancellationToken As CancellationToken) As Task
Remarks
Call this method to specify a stream to read the input EDI data from. The data can then be parsed with Parse.
Validate Method (EDIFACTValidator Component)
Validate the EDI document and warn about any errors encountered.
Syntax
public void Validate(); Async Version public async Task Validate(); public async Task Validate(CancellationToken cancellationToken);
Public Sub Validate() Async Version Public Sub Validate() As Task Public Sub Validate(cancellationToken As CancellationToken) As Task
Remarks
This method parses the input EDI document, firing the ValidateWarning event for any non-blocking errors it encounters.
Error Event (EDIFACTValidator Component)
Fires when an error occurs during message processing. Normally, the component fails with an error.
Syntax
public event OnErrorHandler OnError; public delegate void OnErrorHandler(object sender, EDIFACTValidatorErrorEventArgs e); public class EDIFACTValidatorErrorEventArgs : EventArgs { public int ErrorCode { get; } public string Description { get; } }
Public Event OnError As OnErrorHandler Public Delegate Sub OnErrorHandler(sender As Object, e As EDIFACTValidatorErrorEventArgs) Public Class EDIFACTValidatorErrorEventArgs Inherits EventArgs Public ReadOnly Property ErrorCode As Integer Public ReadOnly Property Description As String End Class
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally, the component throws an exception.
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 Component)
Fires whenever a new EDIFACT message is encountered and no schema is found for it.
Syntax
public event OnResolveSchemaHandler OnResolveSchema; public delegate void OnResolveSchemaHandler(object sender, EDIFACTValidatorResolveSchemaEventArgs e); public class EDIFACTValidatorResolveSchemaEventArgs : EventArgs { public string MessageVersion { get; } public string MessageType { get; } }
Public Event OnResolveSchema As OnResolveSchemaHandler Public Delegate Sub OnResolveSchemaHandler(sender As Object, e As EDIFACTValidatorResolveSchemaEventArgs) Public Class EDIFACTValidatorResolveSchemaEventArgs Inherits EventArgs Public ReadOnly Property MessageVersion As String Public ReadOnly Property MessageType As String End Class
Remarks
This method fires when the component 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 component still doesn't have a matching schema, then it will attempt schema-less parsing of the EDIFACT message.
ValidateWarning Event (EDIFACTValidator Component)
Fires to warn about validation errors.
Syntax
public event OnValidateWarningHandler OnValidateWarning; public delegate void OnValidateWarningHandler(object sender, EDIFACTValidatorValidateWarningEventArgs e); public class EDIFACTValidatorValidateWarningEventArgs : EventArgs { public long Position { get; } public int Line { get; } public int Column { get; } public string ErrorCode { get; } public string ErrorMessage { get; } public int ErrorType { get; } }
Public Event OnValidateWarning As OnValidateWarningHandler Public Delegate Sub OnValidateWarningHandler(sender As Object, e As EDIFACTValidatorValidateWarningEventArgs) Public Class EDIFACTValidatorValidateWarningEventArgs Inherits EventArgs Public ReadOnly Property Position As Long Public ReadOnly Property Line As Integer Public ReadOnly Property Column As Integer Public ReadOnly Property ErrorCode As String Public ReadOnly Property ErrorMessage As String Public ReadOnly Property ErrorType As Integer End Class
Remarks
When the component 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.
Remarks
This type contains fields specifying the various delimiters used within the EDIFACT document.
Fields
Component
string
Default: ":"
The character used to separate the components in a composite element.
Decimal
string
Default: "."
The character used to separate the integer portion of a numeric value from the fractional portion.
Element
string
Default: "+"
The delimiter used to separate elements within a segment.
Release
string
Default: "?"
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
string
Default: "*(syntax 4) or empty(syntax 3)"
The character used to indicate a repeating element or component.
Segment
string
Default: "'"
The character used to terminate a segment.
Constructors
public EDIFACTDelimiters();
Public EDIFACTDelimiters()
EDIFACTValidationErrorDetail Type
Contains the details of a validation error.
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: 0
The column number where the error occurred.
ComponentIndex
int (read-only)
Default: 1
This field holds the position of the element where the error occurred.
ElementIndex
int (read-only)
Default: 1
This field holds the position of the element where the error occurred.
ErrorCode
string (read-only)
Default: "0"
The ErrorCode field contains the type of error encountered.
ErrorMessage
string (read-only)
Default: ""
ErrorMessage is a textual description of the error.
ErrorType
int (read-only)
Default: 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: 1
This field holds the position of the functional group where the error occurred.
InterchangeIndex
int (read-only)
Default: 1
This field holds the position of the interchange where the error occurred.
Line
int (read-only)
Default: 0
The line number where the error occurred.
MessageIndex
int (read-only)
Default: 1
This field holds the position of the message where the error occurred.
Position
long (read-only)
Default: 0
This field holds the byte position in the EDI stream where the error occurred.
SegmentIndex
int (read-only)
Default: 1
This field is the index of the segment where the error occurred.
SegmentTag
string (read-only)
Default: ""
This field specifies the tag name of the segment where the error occurred.
Config Settings (EDIFACTValidator Component)
The component 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 component, access to these internal properties is provided through the Config method.EDIFACTValidator Config Settings
| InputFormat | Meaning |
| 0 (default) | EDIFACT |
| 1 | XML |
Trappable Errors (EDIFACTValidator Component)
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. |