PyXQueryProcessor

class PyXQueryProcessor

Bases: object

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

A PyXQueryProcessor is created by calling PySaxonProcessor.new_xquery_processor(); it has no public constructor.

base_uri

Property to get the static base URI of the query

Returns:

the static base URI

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

declare_namespace(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.

Parameters:
  • prefix (str) – The namespace prefix. If the value is a zero-length string, this method sets the default namespace for elements and types.

  • 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()

Ask whether the streaming option has been set.

Returns:

true if the streaming option has been set.

remove_parameter(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.

Parameters:

name (str) – The name of the query parameter

Returns:

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

Return type:

bool

run_query_to_file(**kwds)

Execute a query with the result saved to file.

Keyword 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) – Path to the input

  • input_xdm_item (PyXdmItem) – The input as an XDM item.

  • query_file (str) – Path to the query file.

  • query_text (str) – The query as a string.

  • lang (str) – which version of XQuery should be used, options: '3.1' or '4.0'.

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

Only one of input_file_name or input_xdm_item, and one of query_file or query_text can be supplied.

Raises:
run_query_to_string(**kwds)

Execute a query and return the result as a string.

Keyword Arguments:
  • input_file_name (str) – Path to the input

  • input_xdm_item (PyXdmItem) – The input as an XDM item.

  • query_file (str) – Path to the query file.

  • query_text (str) – The query as a string.

  • lang (str) – which version of XQuery should be used, options: '3.1' or '4.0'.

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

Only one of input_file_name or input_xdm_item, and one of query_file or query_text can be supplied.

Returns:

Output result as a string

Return type:

str

Raises:
run_query_to_value(**kwds)

Execute a query and return the result as a PyXdmValue object.

Keyword Arguments:
  • input_file_name (str) – Path to the input

  • input_xdm_item (PyXdmItem) – The input as an XDM item.

  • query_file (str) – Path to the query file.

  • query_text (str) – The query as a string.

  • lang (str) – which version of XQuery should be used, options: '3.1' or '4.0'.

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

Only one of input_file_name or input_xdm_item, and one of query_file or query_text can be supplied.

Returns:

Output result as a PyXdmValue

Return type:

PyXdmValue

Raises:
set_context(**kwds)

Set the initial context for the query

Parameters:

**kwds – Possible keyword arguments: file_name (str) or xdm_item (PyXdmItem)

set_cwd(cwd)

Set the current working directory.

Parameters:

cwd (str) – current working directory

set_output_file(output_file)

Set the output file where the result is sent.

Parameters:

output_file (str) – Name of the output file

set_parameter(name, value)

Set the value of a query parameter

Parameters:
  • name (str) – the name of the stylesheet parameter, as a string. For a namespaced parameter use Clark notation "{uri}local"

  • value (PyXdmValue) – the value of the query parameter

set_property(name, value)

Set a property specific to the processor in use.

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

  • value (str) – The value of the property

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

Set the static base URI for the query

Parameters:

base_uri (str) – The static base URI; or None to indicate that no base URI is available

set_query_content(content)

Supply the query as a string

Parameters:

content (str) – The query content supplied as a string

set_query_file(file_name)

Supply the query as a file

Parameters:

file_name (str) – The file name for the query

set_schema_aware(schema_aware)
set_streaming(option)

Say whether the query should be compiled and evaluated to use streaming. Option requires SaxonC-EE.

Parameters:

option (bool) – 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(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.

Parameters:

updating (bool) – 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)