SaxonC 12.7.0
Saxon Processor library for C/C++, PHP and Python
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SchemaValidator Class Reference

#include <SchemaValidator.h>

Public Member Functions

 SchemaValidator ()
 Default constructor.
 
 SchemaValidator (SaxonProcessor *proc, std::string cwd="")
 Constructor with the SaxonProcessor supplied.
 
 SchemaValidator (const SchemaValidator &other)
 SchemaValidator copy constructor.
 
 ~SchemaValidator ()
 Destructor method: at the end of the program call the release() method to clear the JVM.
 
SchemaValidatoroperator= (const SchemaValidator &other)
 The copy assignment= operator.
 
void setcwd (const char *cwd)
 Set the current working directory for the validator.
 
const char * getcwd ()
 Get the current working directory set on this validator.
 
void registerSchemaFromFile (const char *xsd)
 Register the schema from file name.
 
void registerSchemaFromString (const char *schemaStr, const char *systemID=nullptr)
 Register the schema supplied as a string.
 
void registerSchemaFromNode (XdmNode *node)
 Register the schema supplied as an XDM Node Object.
 
void exportSchema (const char *fileName)
 Export a precompiled Schema Component Model.
 
void setOutputFile (const char *outputFile)
 Set the name of the output file that will be used by the validator.
 
const char * getOutputFile ()
 Get the output file that will be used by the validator.
 
void validate (const char *sourceFile=nullptr)
 Validate an instance document by a registered schema.
 
XdmNodevalidateToNode (const char *sourceFile=nullptr)
 Validate an instance document supplied as a Source object.
 
void setSourceNode (XdmNode *source)
 Set the source node for validation.
 
XdmNodegetValidationReport ()
 Get the validation report.
 
void setParameter (const char *name, XdmValue *value, bool withParam=true)
 Set the value of a parameter used in the validator.
 
bool removeParameter (const char *name)
 Remove a parameter (name, value) pair.
 
void setProperty (const char *name, const char *value)
 Set a configuration property specific to the validator in use.
 
void clearParameters (bool deleteValues=false)
 Clear parameter values set.
 
void clearProperties ()
 Clear configuration property values set.
 
XdmValuegetParameter (const char *name, bool withParam=true)
 Get the value of a parameter.
 
std::map< std::string, XdmValue * > & getParameters ()
 Get all parameters as a std::map.
 
std::map< std::string, std::string > & getProperties ()
 Get all configuration properties specified on the processor as a std::map.
 
bool exceptionOccurred ()
 Checks for pending exceptions without creating a local reference to the exception object.
 
const char * checkException ()
 Deprecated.
 
void exceptionClear ()
 Deprecated.
 
const char * getErrorMessage ()
 Deprecated.
 
const char * getErrorCode ()
 Deprecated.
 
void setLax (bool l)
 Set the validation mode - which may be either strict or lax.
 
int64_t getUnderlyingValidator ()
 Get the underlying Java object of the C++ schema validator.
 
SaxonProcessorgetSaxonProcessor ()
 Get the SaxonProcessor which created this SchemaValidator.
 

Detailed Description

A SchemaValidator represents a factory for validating instance documents against a schema.

Constructor & Destructor Documentation

◆ SchemaValidator() [1/3]

SchemaValidator::SchemaValidator ( )

Default constructor.

Creates a Schema Validator

Exceptions
SaxonApiException

◆ SchemaValidator() [2/3]

SchemaValidator::SchemaValidator ( SaxonProcessor * proc,
std::string cwd = "" )

Constructor with the SaxonProcessor supplied.

The supplied processor should have license flag set to true for the Schema Validator to operate.

Parameters
proc- pointer to the SaxonProcessor object
cwd- the current working directory
Exceptions
SaxonApiException

◆ SchemaValidator() [3/3]

SchemaValidator::SchemaValidator ( const SchemaValidator & other)

SchemaValidator copy constructor.

Parameters
other- SchemaValidator

Member Function Documentation

◆ checkException()

const char * SchemaValidator::checkException ( )

Deprecated.

Check for thrown exceptions.

Returns
The main exception message if any has been thrown otherwise return nullptr
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ clearParameters()

void SchemaValidator::clearParameters ( bool deleteValues = false)

Clear parameter values set.

Default behaviour (false) is to leave XdmValues in memory. Individual pointers to XdmValue objects have to be deleted in the calling program.

Parameters
deleteValues- if true then XdmValues are deleted

◆ exceptionClear()

void SchemaValidator::exceptionClear ( )

Deprecated.

Clear any thrown exceptions.

Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ exceptionOccurred()

bool SchemaValidator::exceptionOccurred ( )

Checks for pending exceptions without creating a local reference to the exception object.

Returns
True when there is a pending exception; otherwise false

◆ exportSchema()

void SchemaValidator::exportSchema ( const char * fileName)

Export a precompiled Schema Component Model.

The Component model containing all the components (except built-in components) that have been loaded by using the register methods.

Parameters
fileName- The file name where the exported schema will be stored
Exceptions
SaxonApiException

◆ getcwd()

const char * SchemaValidator::getcwd ( )

Get the current working directory set on this validator.

Memory deallocation is handled internally.

Returns
Current working directory

◆ getErrorCode()

const char * SchemaValidator::getErrorCode ( )

Deprecated.

Get error code if an error is reported. Validation error are reported as exceptions. All errors can be retrieved.

Returns
char* - The error code of the exception.
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getErrorMessage()

const char * SchemaValidator::getErrorMessage ( )

Deprecated.

Get the error message if there are any validation errors. A validation may have a number of errors reported against it.

Returns
The message of the exception
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getOutputFile()

const char * SchemaValidator::getOutputFile ( )

Get the output file that will be used by the validator.

Returns
const char * - string of the output file. Memory deallocation is handled internally.

◆ getParameter()

XdmValue * SchemaValidator::getParameter ( const char * name,
bool withParam = true )

Get the value of a parameter.

Parameters
name- the name of the parameter
withParam- internal use only
Returns
The value of the parameter as an XdmValue. Memory deallocation is handled internally.

◆ getValidationReport()

XdmNode * SchemaValidator::getValidationReport ( )

Get the validation report.

The 'report-node' option must have been set to true in the properties to use this feature: e.g. using setProperty("report-node", true) on the class object.

Returns
XdmNode - Pointer to XdmNode. Return nullptr if validation reporting feature has not been enabled. The caller is responsible for memory deallocation.
Exceptions
SaxonApiException

◆ operator=()

SchemaValidator & SchemaValidator::operator= ( const SchemaValidator & other)

The copy assignment= operator.

Create a copy of the SchemaValidator.

Parameters
other- SchemaValidator object

◆ registerSchemaFromFile()

void SchemaValidator::registerSchemaFromFile ( const char * xsd)

Register the schema from file name.

The schema components derived from this schema document are added to the cache of schema components maintained by this SchemaValidator.

Parameters
xsd- File name of the schema relative to the cwd or full path if cwd is null. The document may be either a schema document in source XSD format, or a compiled schema in Saxon-defined SCM format (as produced using the method exportSchema)
Exceptions
SaxonApiException

◆ registerSchemaFromNode()

void SchemaValidator::registerSchemaFromNode ( XdmNode * node)

Register the schema supplied as an XDM Node Object.

Parameters
node- The schema document supplied as an XdmNode object
Exceptions
SaxonApiException

◆ registerSchemaFromString()

void SchemaValidator::registerSchemaFromString ( const char * schemaStr,
const char * systemID = nullptr )

Register the schema supplied as a string.

Parameters
schemaStr- The schema document supplied as a string
systemID- The system ID of the document supplied as a string
Exceptions
SaxonApiException

◆ removeParameter()

bool SchemaValidator::removeParameter ( const char * name)

Remove a parameter (name, value) pair.

Parameters
name- the name of the parameter
Returns
Outcome of the removal

◆ setcwd()

void SchemaValidator::setcwd ( const char * cwd)

Set the current working directory for the validator.

Parameters
cwd- Supplied working directory which replaces any set cwd. Ignore if cwd is NULL.

◆ setLax()

void SchemaValidator::setLax ( bool l)

Set the validation mode - which may be either strict or lax.

The default is strict; this method may be called to indicate that lax validation is required. With strict validation, validation fails if no element declaration can be located for the outermost element. With lax validation, the absence of an element declaration results in the content being considered valid.

Parameters
l- true if validation is to be lax, false if it is to be strict

◆ setOutputFile()

void SchemaValidator::setOutputFile ( const char * outputFile)

Set the name of the output file that will be used by the validator.

Parameters
outputFilethe output file name for later use

◆ setParameter()

void SchemaValidator::setParameter ( const char * name,
XdmValue * value,
bool withParam = true )

Set the value of a parameter used in the validator.

Parameters
name- the name of the parameter, as a string. For a namespaced name use clark notation i.e. "{uri}local"
value- the value of the parameter, or nullptr to clear a previously set value

◆ setProperty()

void SchemaValidator::setProperty ( const char * name,
const char * value )

Set a configuration property specific to the validator in use.

Parameters
name- the name of the property
value- the value of the property

◆ setSourceNode()

void SchemaValidator::setSourceNode ( XdmNode * source)

Set the source node for validation.

Parameters
source- The source document supplied as an XdmNode, which will be used to validate against the schema using the validate methods. The caller is responsible for deallocation of memory associated with the source node.

◆ validate()

void SchemaValidator::validate ( const char * sourceFile = nullptr)

Validate an instance document by a registered schema.

Parameters
sourceFileName of the file to be validated. Allow nullptr when source document is supplied with other method
Exceptions
SaxonApiException

◆ validateToNode()

XdmNode * SchemaValidator::validateToNode ( const char * sourceFile = nullptr)

Validate an instance document supplied as a Source object.

Parameters
sourceFileThe name of the file to be validated. Default is nullptr
Returns
XdmNode - the validated document returned to the calling program. The caller is responsible for deallocation using delete.
Exceptions
SaxonApiException

The documentation for this class was generated from the following files: