xquery.xpath

The xpath module provides a Python API for the XPath 3.1 specification. This Python interface enables the user to compile an xpath expression and to execute it with different input data. The typical starting point would be the functions xpath.Expression.compile and xpath.Expression.execute.

There are also utility functions xpath.compile and xpath.execute for simplified usage.

>>> seq = execute('fold-left(1 to 7, 2, function($primes, $val){$primes, (2*$val+1)[every $i in $primes satisfies . mod $i]})', session=Session())
>>> TypeConverter().to_python(seq)
(2, 3, 5, 7, 11, 13)

Classes

Enumeration classes

Functions

xquery.xpath.compile(unicode expression_text, *, Session session, **kwargs)

Validate the provided expression_text and create a compiled expression from it. Internally uses the xpath.Expression.create_from_options classmethod but has different return values. Returns an xpath.Expression object on success or raises an exception if there are syntax or static errors detected. The keyword arguments corresponding to the properties of xpath.CompileOptions are supported and are used to initialize the internally created options object.

xquery.xpath.execute(unicode expression_text, *, Session session, initial_context=None, **kwargs)

Compile and execute the xpath expression. Returns an xpath.Sequence, or raises an exception if an error is encountered. The keyword arguments corresponding to the properties of xpath.CompileOptions and xpath.RuntimeOptions are supported and are used in the initialization of the respective objects.

>>> res = execute('year-from-date(current-date()) ge 2018')
>>> res.to_python()
True