Skip to main content

Module api

Module api 

Source
Expand description

High-level, ergonomic XPath evaluation API.

This module provides a user-friendly interface for compiling and evaluating XPath expressions with Rust-idiomatic patterns:

  • Separation of compilation and execution: Compile once, evaluate many times
  • Builder pattern: Fluent API for setting variables and options
  • From traits: Ergonomic value conversion (use 42 instead of XPathValue::integer(42))
  • No lifetimes in compiled expressions: Store XPathExpr anywhere

§Example

use xsd_schema::xpath::api::{XPathExpr, EvalValue};
use xsd_schema::xpath::{XPathContext, RoXmlNavigator};
use xsd_schema::namespace::table::NameTable;

// Setup context
let names = NameTable::new();
let ctx = XPathContext::new(&names);

// Compile once with external variables
let expr = XPathExpr::compile_with_vars("$x + $y", &ctx, &["x", "y"]).unwrap();

// Evaluate with fluent builder
let result = expr.evaluator(&ctx)
    .with_variable("x", 10).unwrap()
    .with_variable("y", 32).unwrap()
    .run::<RoXmlNavigator<'static>>().unwrap();

// Convenience methods for common return types
let sum = expr.evaluator(&ctx)
    .with_variable("x", 20).unwrap()
    .with_variable("y", 22).unwrap()
    .run_number::<RoXmlNavigator<'static>>().unwrap();
assert_eq!(sum, 42.0);

Structs§

ExternalVar
Information about an external variable declared at compile time.
TypedEvaluator
A typed evaluator that allows binding arbitrary XPathValue<N> values.
XPathEvaluator
Builder for evaluating a compiled XPath expression.
XPathExpr
A compiled XPath expression that can be evaluated multiple times.

Enums§

EvalValue
A value that can be bound to an XPath variable at evaluation time.