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
Fromtraits: Ergonomic value conversion (use42instead ofXPathValue::integer(42))- No lifetimes in compiled expressions: Store
XPathExpranywhere
§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§
- External
Var - Information about an external variable declared at compile time.
- Typed
Evaluator - A typed evaluator that allows binding arbitrary
XPathValue<N>values. - XPath
Evaluator - Builder for evaluating a compiled XPath expression.
- XPath
Expr - A compiled XPath expression that can be evaluated multiple times.
Enums§
- Eval
Value - A value that can be bound to an XPath variable at evaluation time.