Skip to main content

kawat_xpath/
lib.rs

1//! XPath evaluation on HTML documents.
2//!
3//! Provides a wrapper around `sxd_html` + `sxd_xpath` for evaluating
4//! XPath 1.0 expressions on HTML, with `scraper` as CSS-selector fallback.
5//!
6//! All XPath expressions from trafilatura's `xpaths.py` use a narrow subset:
7//! `contains()`, `starts-with()`, `translate()`, `self::`, `[1]` positional,
8//! `or`/`and`, and attribute tests. No axes beyond descendant/child.
9
10mod compiled;
11mod error;
12mod eval;
13mod fallback;
14
15pub use compiled::CompiledXpaths;
16pub use error::XpathError;
17pub use eval::XpathEngine;
18
19/// Pre-compiled XPath expression group (thread-safe, reusable).
20pub struct XpathExpr {
21    pub raw: &'static str,
22    // Evaluation is handled by the engine at runtime
23}
24
25impl XpathExpr {
26    pub const fn new(raw: &'static str) -> Self {
27        Self { raw }
28    }
29}