PySaxonProcessor

class PySaxonProcessor

Bases: object

Acts as a factory for generating XQuery, XPath, Schema and XSLT compilers.

This class is itself the context that needs to be managed (i.e. allocation & release)

Example

Creating an XSLT processor and an atomic value:

from saxoncee import *
with PySaxonProcessor(license=False) as proc:
    print("Test SaxonC on Python")
    print(proc.version)
    xdmAtomicval = proc.make_boolean_value(False)
    xslt30proc = proc.new_xslt30_processor()
__enter__()

enter method for use with the keyword ‘with’ context Deprecated. This may be removed in a later release.

__exit__(exception_type, exception_value, traceback)

Deprecated. This method no longer does anything, and may be removed in a later release.

classmethod __new__(*args, **kwargs)
__pyx_vtable__ = <capsule object NULL>
__reduce__()

Helper for pickle.

__setstate__()
attach_current_thread
clark_name_to_eqname(name, encoding=None)

Convert clark name string to EQName notation; i.e. the expanded name.

Uses the notation defined by the EQName production in XPath 3.0. If the name is in a namespace, the resulting string takes the form Q{uri}local. Otherwise, the value is the local part of the name.

Parameters:
  • name (str) – The URI in Clark notation: {uri}local if the name is in a namespace, or simply local if not.

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

the expanded name, as a string using the notation defined by the EQName production

in XPath 3.0.

Return type:

str

clear_configuration_properties(self)

Clear the configuration properties in use by the processor

cwd

Property represents the current working directory

detach_current_thread
edition

Property to get the short name of the licensed Saxon product edition.

This represents the kind of configuration that has been created, rather than the software that has been installed; which depends on the license key supplied, as well as the software edition installed.

Returns:

the Saxon edition code: “EE”, “PE”, or “HE”.

Return type:

str

empty_sequence()

Returns a PyXdmValue representing the empty sequence

Returns:

the empty sequence

Return type:

PyXdmValue

eqname_to_clark_name(name, encoding=None)

Convert EQName string to clark name notation.

Parameters:
  • name (str) – The URI in EQName notation: Q{uri}local if the name is in a namespace. For a name in no namespace, either of the forms Q{}local or simply local are accepted.

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

the URI in clark notation

Return type:

str

get_string_value(item)

Get the string value of the supplied PyXdmItem

Get the string value of the supplied PyXdmItem, as defined in the XPath data model process for stringifying items

Parameters:

item (PyXdmItem) – An XDM item

Returns:

The string value of this XDM item

Return type:

str

is_licensed

Property to check whether a license key has been found and accepted.

Returns:

True if the SaxonC Processor is licensed, or False otherwise

Return type:

bool

is_schema_aware

Property to check if the processor is schema aware.

A licensed SaxonC-EE product is schema aware

Returns:

True if the processor is schema aware, or False otherwise

Return type:

bool

make_array(values)

Make a PyXdmArray whose members are from a list of PyXdmValues

Parameters:

values (list) – List of PyXdmValues

Returns:

The corresponding value

Return type:

PyXdmArray

make_atomic_value(value_type, value, encoding=None)

Create an XDM atomic value from string representation

Parameters:
  • value_type (str) – Local name of a type in the XML Schema namespace

  • value (str) – The value given in a string form. In the case of a QName the value supplied must be in clark notation {uri}local.

  • encoding (str) – The encoding of the value_type. If not specified then the platform default encoding is used.

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_boolean_value(value)

Factory method: makes a PyXdmAtomicValue representing a boolean value

Parameters:

value (bool) – True or False, to determine which boolean value is required

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_double_value(self, value)

Factory method: makes a double value :param value: The supplied primitive double value :type value: double

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_float_value(value)

Factory method: makes a float value

Parameters:

value (float) – The supplied primitive float value

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_integer_value(value)

Create an XDM atomic value representing an integer

Creates either an Int64Value or a BigIntegerValue, depending on the value supplied

Parameters:

value (int) – The supplied primitive integer value

Returns:

The corresponding XDM value which is a BigIntegerValue or Int64Value as appropriate

Return type:

PyXdmAtomicValue

make_long_value(value)

Factory method: makes either an Int64Value or a BigIntegerValue depending on the value supplied

Parameters:

value (long) – The supplied primitive long value

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_map(dataMap: dict[PyXdmAtomicValue, PyXdmValue])

Make a PyXdmMap from a dict of XDM values

Make a PyXdmMap from a dict type whose entries are key-value pairs of type (PyXdmAtomicValue, PyXdmValue). The factory method create_xdm_dict(proc, mmap) can be used to create pairs of type (PyXdmAtomicValue, PyXdmValue) from primitive types, which can then be used as input to this function make_map.

Parameters:

dataMap (dict) – Dictionary of (PyXdmAtomicValue, PyXdmValue) pairs

Returns:

The corresponding value

Return type:

PyXdmMap

Example

mymap = {"a":saxonproc.make_integer_value(1),
    "b":saxonproc.make_integer_value(2),
    "c":saxonproc.make_integer_value(3)}
xdmdict = create_xdm_dict(saxonproc, mymap)
map = saxonproc.make_map(xdmdict)
make_map2(dataMap, encoding=None)

Make a PyXdmMap from a dict of type (str, PyXdmValue).

Make a PyXdmMap from a dict type whose entries are key-value pairs of type (str, PyXdmValue).

Parameters:
  • dataMap (dict) – Dictionary of (str, PyXdmValue) pairs

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

The corresponding value

Return type:

PyXdmMap

make_qname_value(str_, encoding=None)

Create a QName XDM value from string representation in clark notation

Parameters:
  • str (str) – The value given in a string form in clark notation {uri}local

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

The corresponding XDM value

Return type:

PyXdmAtomicValue

make_string_value(value, encoding=None)

Factory method to create an xs:string atomic value as a new PyXdmAtomicValue

Parameters:
  • value (str) – The string value. NULL is taken as equivalent to “”.

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Returns:

The corresponding XDM string value

Return type:

PyXdmAtomicValue

new_document_builder()

Create a PyDocumentBuilder.

A PyDocumentBuilder holds properties controlling how a Saxon document tree should be built, and provides methods to invoke the tree construction.

Returns:

a newly created PyDocumentBuilder

Return type:

PyDocumentBuilder

new_schema_validator()

Create a PySchemaValidator.

This validator which can be used to validate instance documents against the schema held by this processor.

Returns:

a newly created PySchemaValidator

Return type:

PySchemaValidator

new_xpath_processor()

Create a PyXPathProcessor.

A PyXPathProcessor is used to compile and execute XPath expressions.

Returns:

a newly created XPathProcessor

Return type:

PyXPathProcessor

new_xquery_processor()

Create a PyXqueryProcessor.

A PyXQueryProcessor is used to compile and execute XQuery queries.

Returns:

a newly created PyXQueryProcessor

Return type:

PyXQueryProcessor

new_xsd_compiler()

Create a PyXsdCompiler.

The PyXsdCompiler is used to load schema documents, and to set options for the way in which they are loaded. The PyXsdCompiler is new in Saxon 13; it replaces the register_schema method which is retained (but deprecated) to provide a degree of backwards compatibility.</i></p>

Returns:

a newly created PyXsdCompiler

Return type:

PyXsdCompiler

new_xslt30_processor()

Create a PyXslt30Processor.

A PyXslt30Processor is used to compile and execute XSLT 3.0 stylesheets.

Returns:

a newly created PyXslt30Processor

Return type:

PyXslt30Processor

parse_json(**kwds)

Parse a source JSON document

Parse a source JSON document supplied as a lexical representation or source file, and return it as an XDM value

Parameters:

**kwds – Possible keyword arguments: one of the following (json_file_name|json_text) is required. The keyword "encoding" (str) can be used to specify the encoding used to decode the json_text string (if not specified then the platform default encoding is used).

Returns:

The XDM value representation of the JSON document

Return type:

PyXdmValue

Raises:

Exception – Error if invalid use of keywords

parse_xml(**kwds)

Parse a source XML document

Parse a source XML document supplied as a lexical representation, source file or uri, and return it as an XDM node

Parameters:
  • **kwds – Possible keyword arguments: one of the following (xml_file_name|xml_text|xml_uri) is required.

  • 'encoding' (The keyword)

  • used). ((if not specified then the platform default encoding is)

Returns:

The XDM node representation of the XML document

Return type:

PyXdmNode

Raises:

Exception – Error if invalid use of keywords

register_user_function(ns, func, signature_text=None, signature_map=None, encoding=None, use_python_types=False)

PyObject_CallNoArgs(func)

resources_directory

Property represents the resources directory

set_catalog(file_name)

Set the XML catalog to be used in Saxon

This method is now deprecated. Use set_catalog_files

Deprecated since version Use: set_catalog_files() instead.

Parameters:

file_name (str) – The file name for the XML catalog

set_catalog_files(file_names)

Set the XML catalog files to be used in Saxon

Parameters:

file_names (list) – List of strings for the XML catalog file names

set_configuration_property(name, value, encoding=None)

Properties set here are common across all processors.

Set configuration property specific to the processor in use.

Parameters:
  • name (str) – The name of the property

  • value (str) – The value of the property

  • encoding (str) – The encoding of the string. If not specified then the platform default encoding is used.

Example

To enable the line number::

processor.set_configuration_property(‘l’, ‘on’)

‘l’: ‘on’ or ‘off’ - to enable the line number

set_cwd(cwd)

Set the current working directory

Parameters:

cwd (str) – current working directory

set_resources_directory(dir_)

Set the resources directory

Parameters:

dir (str) – A string of the resources directory which Saxon will use

version

Get the Saxon Version.

Returns:

The Saxon version

Return type:

str