Expand description
XPath 1.0 expression parsing and evaluation.
For repeated queries against the same document, create an
XPathContext once — it builds the document index on construction
and amortises that cost across every subsequent eval_* call. The free
functions (xpath_eval, xpath_str, etc.) are one-shot
convenience wrappers that build a fresh context each time; use them when
you only need a single result.
§Example — one-shot helpers
use sup_xml_core::{parse_str, xpath_str, xpath_count, xpath_bool, ParseOptions};
let doc = parse_str(r#"<catalog><book id="1"/><book id="2"/></catalog>"#, &ParseOptions::default()).unwrap();
assert_eq!(xpath_count(&doc, "/catalog/book").unwrap(), 2);
assert_eq!(xpath_str(&doc, "name(/catalog)").unwrap(), "catalog");
assert!(xpath_bool(&doc, "/catalog/book[@id='1']").unwrap());§Example — reusable context
use sup_xml_core::{parse_str, XPathContext, ParseOptions};
let doc = parse_str(r#"<catalog><book id="1"/><book id="2"/></catalog>"#, &ParseOptions::default()).unwrap();
let ctx = XPathContext::new(&doc);
assert_eq!(ctx.eval_count("/catalog/book").unwrap(), 2);
assert!(ctx.eval_bool("/catalog/book[@id='1']").unwrap());Re-exports§
pub use ast::Axis;pub use ast::Expr;pub use ast::LocationPath;pub use ast::NodeTest;pub use ast::Step;pub use ast::FunctionSig;pub use ast::ItemType;pub use ast::Occurrence;pub use ast::SequenceType;pub use context::DocIndex;pub use context::INodeKind;pub use context::is_synthetic_id;pub use eval::Value as XPathValue;pub use eval::compile_xpath_2_0_regex;
Modules§
- ast
- context
- Arena-tree counterpart to
super::context::DocIndex. - eval
- exslt
- EXSLT extension function families — the math, date, str, and set namespaces every real-world XSLT stylesheet (and many bare XPath consumers) reach for.
- pattern
- A small subset of XPath 1.0 sized for fast per-node matching.
- rtf
- XSLT result-tree-fragment storage for XPath navigation.
Structs§
- XPath
Bindings Builder - Builder +
XPathBindingsimpl for caller-supplied namespaces, variables, and extension functions. Cheap to clone (functions are stored inArc). Pass&builder(or any&dyn XPathBindings) tosuper::XPathContext::eval_with. - XPath
Context - Reusable XPath context for an arena-allocated
ArenaDocument. - XPath
Options - Knobs for the XPath 1.0 lexer + evaluator. Default is strict
XPath 1.0 spec conformance; flipping
libxml2_compatiblerelaxes three points where libxml2 historically deviates from the spec:
Enums§
- XPath
Node Kind - Simple, tree-agnostic enum. Used by eval for node-test matching. The
per-tree
INodeKind/INodeKindtypes map onto this viaDocIndexLike::kind.
Constants§
- MAX_
PREDICATE_ NESTING_ DEPTH - Maximum predicate-nesting depth accepted by
parse_xpath_with.
Traits§
- DocIndex
Like - Methods the XPath evaluator needs from any backing tree representation.
Functions§
- parse_
sequence_ type_ str - Parse a
SequenceTypefrom its lexical form ("xs:long","element(e)","function(*)?", …). Used to reconstruct a user function’s declared signature for function-subtyping checks. ReturnsNoneon a lex/parse error or trailing input. - parse_
xpath - Parse an XPath 1.0 expression string into its AST representation
using the default strict options. See
parse_xpath_withto opt into libxml2-compatible lexing. - parse_
xpath_ with - Parse an XPath expression with explicit
XPathOptions. Today the only knob that affects parsing islibxml2_compatible, which makes the lexer accept exponent-notation in number literals. - xpath_
bool - xpath_
count - xpath_
eval - One-shot XPath evaluation against an arena document. Builds a fresh
index per call — use
XPathContextto amortise. - xpath_
num - xpath_
str - xpath_
strings
Type Aliases§
- NodeId
- Index into a flat per-document node table. Zero is the synthetic Document
node; every other index points to the corresponding entry in the per-tree
implementation’s
nodesvector.