module

Mica::XML::XPath

XPath 1.0 over Mica::XML::Document trees.

Supported: the full XPath 1.0 expression grammar (location paths, abbreviations, predicates, filter expressions, unions, arithmetic, comparisons, variables); the axes child, descendant, descendant-or-self, self, parent, ancestor, ancestor-or-self, following, following-sibling, preceding, preceding-sibling and attribute; all node tests; and the core function library except id() and lang(). The namespace axis, id() and lang() raise Mica::XML::XPathError. See the README for the grammar.

document = Mica::XML.parse(%(<a><b n="1"/><b n="2"/></a>))
expression = Mica::XML::XPath.compile("//b[@n > 1]")
expression.evaluate(document.node) # => [#<Mica::XML::Node ELEMENT_NODE name="b">]

Constants

DEFAULT_WORK_BUDGET = Core::WorkBudget.new(operations_per_unit: 64, base_operations: 1000000, timeout: 10.seconds)

The default work budget for one evaluation: 64 operations per node of the document, plus 1,000,000, and at most 10 seconds. Each axis step with position-free predicates is linear in the document, so ordinary queries use a small fraction of it; nested and positional predicates multiply, and the budget stops them.

MAX_SIGNIFICANT_DIGITS = 800

Significant digits kept when converting a decimal string; enough for correct rounding of any binary64 value once a sticky digit is added.

Class methods

compile(path : String, meter : Core::WorkMeter | Nil = nil) : Expression

Parses path. Raises Mica::XML::XPathError on a syntax error or an unsupported feature. Lexing and parsing are charged to meter (one operation per byte and per token, with the expression's bytes as units), or to a fresh meter on DEFAULT_WORK_BUDGET, and stop with a positioned Mica::LimitExceededError when it runs out.

Source
to_xpath_boolean(value : Value) : Bool

Converts value with the XPath boolean() rules.

Source
to_xpath_number(value : Value) : Float64

Converts value with the XPath number() rules.

Source
to_xpath_string(value : Value) : String

Converts value with the XPath string() rules.

Source

Nested types