PyXPathProcessor¶
- class PyXPathProcessor¶
Bases:
objectA PyXPathProcessor represents a factory to compile, load and execute XPath expressions.
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¶
get_base_uri(self) Get the static base URI for XPath expressions compiled using this XPathCompiler. The base URI is part of the static context, and is used to resolve any relative URIs appearing within an XPath expression, for example a relative URI passed as an argument to the doc() function. If no static base URI is supplied, then the current working directory is used. :returns: the base output URI as a string representation of the URI :rtype: str
- clear_parameters()¶
clear_parameter(self) Clear all parameters set on the processor
- clear_properties()¶
clear_parameter(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 XPath expressions compiled using this processor :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 (uri) – 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.
- declare_variable(self, str name)¶
Declare a variable as part of the static context for XPath expressions compiled using this processor. It is an error for the XPath expression to refer to a variable unless it has been declared. This method declares the existence of the variable, but it does not bind any value to the variable; that is done later, when the XPath expression is evaluated. The variable is allowed to have any type (that is, the required type is item()*). Args: name (str): The name of the variable, as a string in clark notation
- effective_boolean_value(self, xpath_str)¶
Evaluate the XPath expression, returning the effective boolean value of the result. :param xpath_str: XPath expression supplied as a string :type xpath_str: str :param encoding: The encoding of the XPath string. Argument can be omitted or None.
If not specified then the platform default encoding is used.
- Returns:
The result is a boolean value.
- Return type:
boolean
- Raises:
PySaxonApiError – Error if failure to evaluate XPath expression
- evaluate(self, xpath_str)¶
Evaluate an XPath expression supplied as a string :param xpath_str: The XPath expression supplied as a string :type xpath_str: str :param encoding: The encoding of the XPath string. Argument can be omitted or None.
If not specified then the platform default encoding is used.
- Returns:
the result of evaluating the XPath expression. Returns None if the expression returns an empty sequence.
- Return type:
- Raises:
PySaxonApiError – Error if failure to evaluate XPath expression
- evaluate_single(self, xpath_str)¶
Evaluate an XPath expression supplied as a string, returning a single item :param xpath_str: The XPath expression supplied as a string :type xpath_str: str :param encoding: The encoding of the XPath string. Argument can be omitted or None.
If not specified then the platform default encoding is used.
- Returns:
A single XDM item is returned. Returns None if the expression returns an empty sequence. If the expression returns a sequence of more than one item, any items after the first are ignored.
- Return type:
- Raises:
PySaxonApiError – Error if failure to evaluate XPath expression
- get_property(self)¶
Get a property value set on the processor specified by name :param name: the name of the property :type name: str
- Returns:
value of the property
- Return type:
- import_schema_namespace(self, uri)¶
Import a schema namespace Args: uri (str): The schema namespace to be imported. To import declarations in a no-namespace schema,
supply a zero-length string.
- is_schema_aware()¶
- remove_parameter(self, name)¶
Remove the parameter given by name from the PyXPathProcessor. The parameter will not have any effect on the XPath if it has not yet been executed. :param name: The name of the XPath parameter :type name: str
- Returns:
True if the removal of the parameter has been successful, False otherwise.
- Return type:
- set_backwards_compatible(self, option)¶
Say whether XPath 1.0 backwards compatibility mode is to be used :param option: true if XPath 1.0 backwards compatibility is to be enabled, false if it is to be disabled. :type option: bool
- set_base_uri(self, base_uri)¶
Set the static base URI for XPath expressions compiled using this XPathCompiler. The base URI is part of the static context, and is used to resolve any relative URIs appearing within an XPath expression, for example a relative URI passed as an argument to the doc() function. If no static base URI is supplied, then the current working directory is used. :param base_uri: the base output URI :type base_uri: str
- set_caching(self, is_caching)¶
Say whether the compiler should maintain a cache of compiled expressions. Args: is_caching (bool): if set to true, caching of compiled expressions is enabled.
If set to false, any existing cache is cleared, and future compiled expressions will not be cached until caching is re-enabled. The cache is also cleared (but without disabling future caching) if any method is called that changes the static context for compiling expressions, for example declare_variable() or declare_namespace().
- set_context(self, **kwds)¶
Set the initial context for the XPath expression :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_language_version(self, version)¶
Say whether an XPath 2.0, XPath 3.0, XPath 3.1 or XPath 4.0 processor is required. :param value: One of the values 1.0, 2.0, 3.0, 3.05, 3.1, 4.0. :type value: str
- set_parameter(self, name, value)¶
Set the value of an XPath parameter :param name: the name of the XPath parameter, as a string. For a namespaced parameter use
clark notation {uri}local
- Parameters:
value (PyXdmValue) – the value of the query parameter, or NULL to clear a previously set value
- set_property(self, name, 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
PyXPathProcessor: set serialization properties (names start with ‘!’ i.e. name “!method” -> “xml”) ‘resources’: directory to find Saxon data files, ‘s’: source as file name, ‘extc’: Register native library to be used with extension functions
- set_schema_aware(schema_aware)¶
- set_unprefixed_element_matching_policy(self, int policy)¶
Set the policy for matching unprefixed element names in XPath expressions. Possible int values: DEFAULT_NAMESPACE = 0, ANY_NAMESPACE = 1 or DEFAULT_NAMESPACE_OR_NONE = 2 Args: policy (int): The policy to be used
- use_schema(schema: PyXsdSchema)¶