Skip to main content

Crate quarb_xpath

Crate quarb_xpath 

Source
Expand description

XPath 1.0 importer for Quarb.

Translates an XPath 1.0 expression into an equivalent Quarb query, following the mapping in the specification’s comparative guide. The translatable subset covers the axes and predicate forms Quarb models directly; everything else is refused with an XPathError::Unsupported naming the construct, never silently approximated.

  • Axes: child, descendant, parent (..), ancestor, self (.), attribute (@), following-sibling (>>), preceding-sibling (<<). No following/preceding (document-order) or namespace axes.
  • Node tests: names (namespace-prefixed names become quoted Quarb segments), *, and terminal text(). No node(), comment(), or processing-instruction(): Quarb navigates elements only.
  • Predicates: positional [n], [last()][-1] (and [last() - k][-(k+1)]), position() comparisons → index / range predicates ([position() > 1][2..]), comparisons over attributes, text(), . and relative descending paths, existence tests, and/or/not(), contains(), starts-with().
  • Top level: union | becomes ||; count(...) and sum(...) become @| count / @| sum aggregations.

Known semantic divergences are reported as Translation::notes rather than errors:

  • [n] on an abbreviated // step: XPath expands //name[n] to a per-parent child:: step, positioning within each parent, while Quarb positions within the hop’s whole per-source result list. The two agree when all matches share one parent. On the child axis (name[n]) and the explicit descendant axis (descendant::name[n]) the translation is exact.
  • Quarb’s ::text is the concatenated descendant text, while XPath’s text() selects immediate text-node children. The two agree on leaf elements.

Structs§

Translation
A successful translation: the Quarb query, plus notes on known semantic divergences that apply to it.

Enums§

XPathError
An error translating an XPath expression.

Functions§

export
Translate a Quarb query to an XPath 1.0 expression.
translate
Translate an XPath 1.0 expression to a Quarb query.