beta.xpath.Expression

The beta.xpath.Expression class represents a valid, compiled xpath expression. It can be instantiated with the beta.xpath.Expression.compile() classmethod. The same beta.xpath.Expression can be used for multiple executions with different beta.xpath.RuntimeOptions.

There is also a utility function beta.xpath.compile() that can be used to create an beta.xpath.Expression.

>>> session = Session()
>>> compile_options = CompileOptions(session)
>>> expr, log = Expression.compile('//*', compile_options)
>>> if expr is None:
>>>     raise Exception("Error creating xpath expression", log)
>>> runtime_options = RuntimeOptions(session)
>>> runtime_options.initial_context = NodeItem.create_from_instance(:meth:`xml.Instance.create_from_buffer`(b'<?xml version="1.0"?><foo><bar>baz</bar></foo>')[0], session)
>>> seq, log = expr.execute(runtime_options)
>>> if seq is None:
>>>     raise Exception("Error executing xpath expression", log)
>>> for i in seq:
>>>     print(i.informationItem().local_name)

Base class: beta.xslt.xpath.Executable -> beta.xslt.xpath.Module

class beta.xpath.Expression

Class methods

classmethod beta.xpath.Expression.compile(type cls, unicode text, CompileOptions options)

Compiles a new beta.xpath.Expression from the provided expression text and beta.xpath.CompileOptions. This involves syntax checking, building of AST, initializing of static context components and static-analysis. In case of a syntax or a static error, the beta.xpath.Expression is None and the xml.ErrorLog contains the error(s).

Returns: (beta.xpath.Expression, xml.ErrorLog)

>>> s = Session()
>>> expr, log = Expression.compile('year-from-date(current-date()) ge 2018', CompileOptions(s))
>>> if expr None:
>>>     print(log)
>>> else:
>>>     print('success')
True

Attributes

beta.xslt.xpath.Module.location
beta.xslt.xpath.Executable.referenced_modules
beta.xslt.xpath.Module.schema
beta.xslt.xpath.Module.strip_input_type_annotations
beta.xslt.xpath.Module.whitespace_handler

Methods

beta.xslt.xpath.Expression.execute(RuntimeOptions options)

Execute the compiled beta.xpath.Expression with the provided beta.xpath.RuntimeOptions. In case of a runtime error the returned beta.xpath.Sequence is None and the xml.ErrorLog contains the error.

Returns: (beta.xpath.Sequence, xml.ErrorLog)

>>> s = Session()
>>> expr, log = Expression.compile('year-from-date(current-date()) ge 2018', CompileOptions(s))
>>> seq, log = expr.execute(RuntimeOptions(s))
>>> seq[0].anySimpleType().value
True
beta.xslt.xpath.Module.load_xml_document(unicode uri, f)

Special methods

__eq__, __ge__, __gt__, __le__, __lt__, __ne__