PySaxonProcessor¶
- class PySaxonProcessor¶
Bases:
objectActs 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()
- 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:
- Returns:
the expanded name, as a string using the notation defined by the EQName production in XPath 3.0.
- Return type:
- clear_configuration_properties()¶
Clear the configuration properties in use by the processor
- cwd¶
Property represents the current working directory
- detach_current_thread¶
- edition¶
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:
- empty_sequence()¶
Returns a PyXdmValue representing the empty sequence
- Returns:
the empty sequence
- Return type:
- eqname_to_clark_name(name, encoding=None)¶
Convert EQName string to clark name notation.
- Parameters:
- Returns:
the URI in clark notation
- Return type:
- 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
- is_licensed¶
Returns whether a license key has been successfully found and accepted.
- Returns:
True if the SaxonC Processor is licensed, or False otherwise
- Return type:
- 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:
- 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:
- 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:
- 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:
- make_double_value(value)¶
Factory method: makes a double value
- Parameters:
value (double) – The supplied primitive double value
- Returns:
The corresponding XDM value
- Return type:
- 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:
- 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:
- 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:
- 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.- Parameters:
dataMap (dict) – Dictionary of (PyXdmAtomicValue, PyXdmValue) pairs
- Returns:
The corresponding value
- Return type:
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).
- make_qname_value(str_, encoding=None)¶
Create a QName XDM value from string representation in clark notation
- Parameters:
- Returns:
The corresponding XDM value
- Return type:
- make_string_value(value, encoding=None)¶
Factory method to create an xs:string atomic value as a new PyXdmAtomicValue
- Parameters:
- Returns:
The corresponding XDM string value
- Return type:
- 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:
- 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:
- new_xpath_processor()¶
Create a PyXPathProcessor.
A PyXPathProcessor is used to compile and execute XPath expressions.
- Returns:
a newly created XPathProcessor
- Return type:
- new_xquery_processor()¶
Create a PyXqueryProcessor.
A PyXQueryProcessor is used to compile and execute XQuery queries.
- Returns:
a newly created PyXQueryProcessor
- Return type:
- 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.
- Returns:
a newly created PyXsdCompiler
- Return type:
- 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:
- 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.
One (and only one) of
json_file_nameorjson_textmust be provided.- Keyword Arguments:
- Returns:
The XDM value representation of the JSON document
- Return type:
- 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.
One (and only one) of
xml_file_name,xml_text, orxml_urimust be provided.- Keyword Arguments:
- Returns:
The XDM node representation of the XML document
- Return type:
- 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)¶
Registers an extension function for use within XSLT, XPath, or XQuery.
- Parameters:
ns (str) – The namespace URI for the function.
func (callable) – The Python function that will be called.
signature_text (str) – The XPath function signature as a JSON string.
signature_map (dict) – The XPath function signature as a dictionary.
use_python_types (bool) – Whether to convert XPath function arguments, and the return value, to/from native Python types.
The XPath signature (XPath local-name, return type and argument types) is specified using a JSON string or dict. That object has the following structure:
{ "function-name": { "as": "xs:integer", "param": [ "xs:integer", "xs:boolean?" ] } }
See Writing extension functions in Python for more details.
- 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:
Example
To enable the line number:
processor.set_configuration_property('l', 'on')
‘l’: ‘on’ or ‘off’ - to enable the line number