PySchemaValidator

class PySchemaValidator

Bases: object

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

Creates a new instance, keeping a reference to its PySaxonProcessor :param processor:

__init__()

Creates a new instance, keeping a reference to its PySaxonProcessor :param processor:

classmethod __new__(*args, **kwargs)
__reduce__()

Helper for pickle.

__setstate__()
clear_parameters()

clear_parameter(self) Clear all parameters set on the processor

clear_properties(self)

Clear all properties set on the processor

cwd

Property represents the current working directory

export_schema(self, file_name)

Export a precompiled Schema Component Model containing all the components (except built-in components) that have been loaded :param file_name: The file name that will be used for the saved SCM :type file_name: str

get_output_file(self)

Set the name of the output file that will be used by the validator. :param Returns: str: The output file name used for use by the validator

register_schema(self, **kwds)

Register a schema supplied as file name, schema text, or XDM node :param **kwds: Possible keyword arguments: must be one of the following (xsd_text|xsd_file|xsd_node)

deprecated:

remove_parameter(self, 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. :param name: The name of the schema parameter :type name: str

Returns:

True if the removal of the parameter has been successful, False otherwise.

Return type:

bool

set_cwd(self, cwd)

Set the current working directory :param cwd: current working directory :type cwd: str

set_lax(self, 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. :param lax: True if validation is to be lax, False if it is to be strict :type lax: bool

set_output_file(self, output_file)

Set the name of the output file that will be used by the validator. :param output_file: The output file name for use by the validator :type output_file: str

set_parameter(self, name, PyXdmValue value)

Set the value of a parameter for the Schema validator :param name: the name of the schema parameter, as a string. For a namespaced parameter use

clark notation {uri}local

Parameters:

value (PyXdmValue) – the value of the parameter, or NULL to clear a previously set value

set_property(self, name, value, encoding=None)

Set a property specific to the processor in use. :param name: The name of the property :type name: str :param value: The value of the property :type value: str :param encoding: The encoding of the name argument. Argument can be omitted or None.

If not specified then the platform default encoding is used.

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(self, PyXdmNode source)

Set the source node for validation :param source: the source node to be validated :type source: PyXdmNode

validate(self, **kwds)

Validate an instance document by a registered schema. :param **kwds: Possible keyword arguments: must be one of the following (file_name|xdm_node|xml_text).

Specifies the source file to be validated. Allow None when source document is supplied using the set_source_node method

Raises:
  • Exception – Error if incorrect keyword used, options available: file_name|xdm_node|xml_text

  • 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(self, **kwds)

Validate an instance document by a registered schema, returning the validated document. :param **kwds: Possible keyword arguments: must be one of the following (file_name|xdm_node|xml_text).

Specifies the source file to be validated. Allow None when source document is supplied using the set_source_node method.

Returns:

The validated document returned to the calling program as a PyXdmNode

Return type:

PyXdmNode

Raises:
  • Exception – Error if incorrect keyword used, options available: file_name|xdm_node|xml_text

  • 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 :rtype: PyXdmNode

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)