Generated Validation Functions

Procedure for Calling C Validation Functions

The -validor -genvalidoption causes validation functions to be generated. These functions can be used to validate a given XML instance against the compiled schema type. They are similar to decode functions in that either the pull-parser or generated SAX handlers are used to parse an XML instance. The handlers in this case do not fully decode the instance; instead, they just check that the instance satisifies all of the constraints specified in the schema.

The generated validation functions are written to a .c file with a name of the following format:


where <xsdFileName>is the base name of the XSD file being parsed. For example, if code is being generated for file x.xsdand -validis specified, validation functions will be written to xVldt.c. If the file being processed is a WSDL file, the suffix would be WSDLVldt.c(for example, x.wsdlwould produce xWSDLVldt.c).

The format of the name of each generated validation function is as follows:


where <elemName>is the name of the XSD global element for which the function is being generated and <ns>is an optional namespace setting that can be used to disambiguate names from multiple sources (note: this should not be confused with XML namespaces which are different). Note that validation functions are only generated for global elements, not types.

When the -genFactoryoption is also specified, factory validation function is generated. The format of the generated factory validation function is as follows:


where <prjName>is the name of the project for which the function is being generated and <ns>is an optional namespace setting.

The calling sequence for each generated test function is as follows:

    OSBOOL result = <validationFunc> (OSCTXT* pctxt);

In this definition, <validationFunc> denotes the formatted function name defined above.

The pctxtargument is used to hold a context pointer to keep track of dynamic memory allocation parameters. This is a basic "handle" variable that is used to make the function reentrant so that it can be used in an asynchronous or threaded application. The user is required to supply a pointer to a variable of this type declared somewhere in his or her program. The variable must be initialized using either the rtxInitContextor rtXmlInitContextrun-time function before use.

The result function return code is a boolean variable indicating whether the message is valid or not. If the message is not valid, reasons for failure will be stored on the error list within the context. The rtxErrfunctions can be used to examine this list (see the XBinder C/C++ Run-time Reference Manualfor details). The simplest way to access this information is to call rtxErrPrintwhich will print details on all errors to stderr.