PySchemaValidator¶
- class PySchemaValidator¶
Bases:
objectA PySchemaValidator represents a factory for validating instance documents against a schema.
Creates a new instance, keeping a reference to its PySaxonProcessor
- Parameters:
processor (PySaxonProcessor)
- clear_parameters()¶
Clear all parameters set on the processor
- clear_properties()¶
Clear all properties set on the processor
- cwd¶
Property represents the current working directory
- export_schema(file_name)¶
Export a precompiled Schema Component Model containing all the components (except built-in components) that have been loaded
- Parameters:
file_name (str) – The file name that will be used for the saved SCM
- get_output_file()¶
Get the name of the output file that will be used by the validator.
- Returns:
The output file name used for use by the validator
- Return type:
- register_schema(**kwds)¶
Deprecated since version 13.0.
Register a schema supplied as file name, schema text, or XDM node
- remove_parameter(name)¶
Remove the parameter given by name from the PySchemaValidator. The parameter will not have any effect on the validation if it has not yet been executed.
- set_lax(lax)¶
The validation mode 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:
lax (bool) – True if validation is to be lax, False if it is to be strict
- set_output_file(output_file)¶
Set the name of the output file that will be used by the validator.
- Parameters:
output_file (str) – The output file name for use by the validator
- set_parameter(name, value)¶
Set the value of a parameter for the Schema validator.
- Parameters:
name (str) – the name of the schema parameter, as a string. For a namespaced parameter use Clark notation
'{uri}local'.value (PyXdmValue) – the value of the parameter, or
Noneto clear a previously set value.
- set_property(name, value, encoding=None)¶
Set a property specific to the processor in use.
- Parameters:
Example
PySchemaValidator: set serialization properties (names start with ‘!’ i.e. name “!method” -> “xml”) ‘o’: output file name, ‘dtd’: Possible values ‘on’ or ‘off’ to set DTD validation, ‘resources’: directory to find Saxon data files, ‘s’: source as file name, ‘string’: Set the source as xml string for validation. Parsing will take place in the validate method ‘report-node’: Boolean flag for validation reporting feature. Error validation failures are represented
in an XML document and returned as a PyXdmNode object
- ‘report-file’: Specify value as a file name string. This will switch on the validation reporting feature,
which will be saved to the file in an XML format
‘verbose’: boolean value which sets the verbose mode to the output in the terminal. Default is ‘on’ ‘element-type’: Set the name of the required type of the top-level element of the document to be validated.
The string should be in clark notation {uri}local
‘lax’: Boolean to set the validation mode to strict (False) or lax (‘True’)
- set_source_node(source)¶
Set the source node for validation
- Parameters:
source (PyXdmNode) – the source node to be validated
- validate(**kwds)¶
Validate an instance document by a registered schema.
- Keyword Arguments:
One and only one of the keyword arguments should be supplied. If the source document to be validated was supplied using
set_source_node(), then no argument needs to be supplied.- Raises:
Exception – If invalid arguments are provided.
PySaxonApiError – if the source document is found to be invalid, or if error conditions occur that prevented validation from taking place (such as failure to read or parse the input document).
- validate_to_node(**kwds)¶
Validate an instance document by a registered schema, returning the validated document.
- Keyword Arguments:
One and only one of the keyword arguments should be supplied. If the source document to be validated was supplied using
set_source_node(), then no argument needs to be supplied.- Returns:
The validated document returned to the calling program as a PyXdmNode
- Return type:
- Raises:
Exception – If invalid arguments are provided.
PySaxonApiError – if the source document is found to be invalid, or if error conditions occur that prevented validation from taking place (such as failure to read or parse the input document).
- validation_report¶
Get the validation report
- Returns:
The Validation report result from the Schema validator
- Return type:
- Raises:
PySaxonApiError – if the source document is found to be invalid, or if error conditions occur
that prevented validation from taking place (such as failure to read or parse the input document) –