PyXQueryProcessor

class PyXQueryProcessor

Bases: object

A PyXQueryProcessor represents a factory to compile, load and execute queries.

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__()
base_uri

Property to get the static base URI of the query :returns: the static base URI

clear_parameters(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

declare_namespace(self, prefix, uri)

Declare a namespace binding as part of the static context for queries compiled using this processor. This binding may be overridden by a binding that appears in the query prolog. The namespace binding will form part of the static context of the query, but it will not be copied into result trees unless the prefix is actually used in an element or attribute name. :param prefix: The namespace prefix. If the value is a zero-length string, this method sets the default

namespace for elements and types.

Parameters:

uri (str) – The namespace URI. It is possible to specify a zero-length string to “undeclare” a namespace; in this case the prefix will not be available for use, except in the case where the prefix is also a zero length string, in which case the absence of a prefix implies that the name is in no namespace.

is_schema_aware()
is_streaming(self, bool option)

Ask whether the streaming option has been set. :returns: true if the streaming option has been set.

remove_parameter(self, name)

Remove the parameter given by name from the PyXQueryProcessor. The parameter will not have any effect on the query if it has not yet been executed. :param name: The name of the query parameter :type name: str

Returns:

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

Return type:

bool

run_query_to_file(self, **kwds)

Execute a query with the result saved to file. :param **kwds: Possible arguments: output_file_name (str) to specify the output file, if

omitted then the output file name needs to be supplied as a property; input_file_name (str) or input_xdm_item (PyXdmItem) can be used to supply the input; query_file (str) or query_text (str) can be used to supply the query; lang (str) can be used to specify which version of XQuery should be used, options: ‘3.1’ or ‘4.0’. Also accept the keyword ‘encoding’ (str) to specify the encoding of the query_text string is specified. If not specified then the platform default encoding is used.

Raises:
run_query_to_string(self, **kwds)

Execute a query and return the result as a string. :param **kwds: Possible keyword arguments: input_file_name (str) or input_xdm_item (PyXdmItem) can be used to

supply the input; query_file (str) or query_text (str) can be used to supply the query; lang (str) can be used to specify which version of XQuery should be used, options: ‘3.1’ or ‘4.0’. Also accept the keyword ‘encoding’ (str) to specify the encoding of the query_text string is specified. If not specified then the platform default encoding is used.

Returns:

Output result as a string

Return type:

str

Raises:
run_query_to_value(self, **kwds)

Execute a query and return the result as a PyXdmValue object. :param **kwds: Possible keyword arguments: input_file_name (str) or input_xdm_item (PyXdmItem) can be used to

supply the input; query_file (str) or query_text (str) can be used to supply the query; lang (str) can be used to specify which version of XQuery should be used, options: ‘3.1’ or ‘4.0’. Also accept the keyword ‘encoding’ (str) to specify the encoding of the query_text string is specified. If not specified then the platform default encoding is used.

Returns:

Output result as a PyXdmValue

Return type:

PyXdmValue

Raises:
set_context(self, **kwds)

Set the initial context for the query :param **kwds: Possible keyword arguments: file_name (str) or xdm_item (PyXdmItem)

set_cwd(self, cwd)

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

set_output_file(self, output_file)

Set the output file where the result is sent :param output_file: Name of the output file :type output_file: str

set_parameter(self, name, PyXdmValue value)

Set the value of a query parameter :param name: the name of the stylesheet parameter, as a string. For a namespaced parameter use

clark notation {uri}local

Parameters:

value (PyXdmValue) – the value of the query parameter

set_property(self, name, str value)

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

Example

PyXQueryProcessor: 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,

set_query_base_uri(self, base_uri)

Set the static base URI for the query :param base_uri: The static base URI; or None to indicate that no base URI is available :type base_uri: str

set_query_content(self, str content)

Supply the query as a string :param content: The query content supplied as a string :type content: str

set_query_file(self, file_name)

Supply the query as a file :param file_name: The file name for the query :type file_name: str

set_schema_aware(schema_aware)
set_streaming(self, bool option)

Say whether the query should be compiled and evaluated to use streaming. Option requires SaxonC-EE. :param option: if true, the compiler will attempt to compile a query to be capable of executing in

streaming mode. If the query cannot be streamed, a compile-time exception is reported. In streaming mode, the source document is supplied as a stream, and no tree is built in memory. The default is false.

set_updating(self, updating)

Say whether the query is allowed to be updating. XQuery update syntax will be rejected during query compilation unless this flag is set. XQuery Update is supported only under SaxonC-EE. :param updating: true if the query is allowed to use the XQuery Update facility (requires SaxonC-EE).

If set to false, the query must not be an updating query. If set to true, it may be either an updating or a non-updating query.

use_schema(schema: PyXsdSchema)