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¶
- xpath.ArrayItem
- xpath.AtomicItem
- xpath.Breakpoint
- xpath.BreakpointList
- xpath.CallStackItem
- xpath.CancelFlag
- xpath.CompileError
- xpath.CompileOptions
- xpath.Debugger
- xpath.DecimalFormat
- xpath.DeleteUpdatePrimitive
- xpath.DynamicContext
- xpath.Error
- xpath.Executable
- xpath.Expression
- xpath.ExtensionItem
- xpath.ExternalFunctionObject
- xpath.ExternalFunctions
- xpath.FunctionItem
- xpath.InsertAfterUpdatePrimitive
- xpath.InsertAttributesUpdatePrimitive
- xpath.InsertBeforeUpdatePrimitive
- xpath.InsertIntoAsFirstUpdatePrimitive
- xpath.InsertIntoAsLastUpdatePrimitive
- xpath.InsertIntoUpdatePrimitive
- xpath.InsertUpdatePrimitive
- xpath.Instruction
- xpath.InstructionList
- xpath.Item
- xpath.MapItem
- xpath.Module
- xpath.NodeItem
- xpath.PutUpdatePrimitive
- xpath.RenameUpdatePrimitive
- xpath.ReplaceElementContentUpdatePrimitive
- xpath.ReplaceNodeUpdatePrimitive
- xpath.ReplaceValeUpdatePrimitive
- xpath.ReplaceValueUpdatePrimitive
- xpath.Result
- xpath.ResultList
- xpath.RuntimeError
- xpath.RuntimeOptions
- xpath.Sequence
- xpath.SerializationParams
- xpath.Session
- xpath.TextLocation
- xpath.Tracepoint
- xpath.TracepointList
- xpath.TypeConverter
- xpath.UpdatePrimitive
- xpath.Variable
- xpath.WhitespaceHandler
- xpath.XmlDocumentOptions
Enumeration classes¶
Functions¶
- 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.Expressionobject on success or raises an exception if there are syntax or static errors detected. The keyword arguments corresponding to the properties of- xpath.CompileOptionsare supported and are used to initialize the internally created options object.
- 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.CompileOptionsand- xpath.RuntimeOptionsare supported and are used in the initialization of the respective objects.
 - res = execute('year-from-date(current-date()) ge 2018') res.to_python() True 
