Crate xrust[][src]

Expand description

A Rust implementation of the XQuery and XPath Data Model 3.1.

The library separates parsing from evaluation. An expression is compiled to create a ‘Sequence Constructor’. This constructor is then applied to a source document to produce a Sequence.

A Sequence is an ordered collection of zero or more Items, implemented as a Rust Vector. An Item is a Node, Function or atomic Value.


let xdoc = roxmltree::Document::parse("<Test/>").expect("parsing XML failed");
let d = vec![Rc::new(Item::XNode(xdoc.root().first_child().unwrap()))];
let xpath = parse("/child::Test").expect("XPath parsing failed");
let dc = DynamicContext::new();
let seq = evaluate(
  &dc,
  Some(d), Some(0),
  &xpath
).expect("evaluation failed");
assert_eq!(seq.len(), 1);
assert_eq!(seq[0].to_name(), "Test");

An explanation of the above example:

  1. The roxmltree crate is used to create an XML document.
  2. A Sequence is created with one item: the document we just created.
  3. Parse an XPath expression. This results in a sequence constructor.
  4. Evaluate the sequence constructor.
    1. A default DynamicContext is provided.
    2. The Sequence created earlier is provided as the initial context for the evaluation.
  5. The evaluation should return a sequence with one item.
  6. That item is the root element of the original XML document.

See the xslt module for an example of how to evaluate an XSL stylesheet.

Status

The project, so far, is a proof-of-concept.

For XPath it provides most of v1.0 functionality, with some v2.0 and v3.2 features.

For XSLT, the implementation has barely started. To begin with it only supports literal result elements and literal text.

The library has not been extensively tested.

Plan

  1. Implement a v3.1 XSLT engine.

Goals / Future Work

  • The library should always return errors, i.e. it should not panic
  • The library should use Traits for tree navigation and construction
  • Make the library more idiomatically Rust

Contributions

We need your help!

  • Download the crate and try it out. Tell us what you like or don’t like. How can it be improved?
  • Let us know what doesn’t work. Submit a bug report.
  • Do you need more documentation? There can never be enough!
  • Add some tests.
  • Write some code.
  • Donate resources (i.e. $$$)

Re-exports

pub use xdmerror::Error;
pub use xdmerror::ErrorKind;
pub use item::Sequence;
pub use item::Item;
pub use item::Value;
pub use item::SequenceTrait;
pub use xpath::parse;
pub use evaluate::StaticContext;
pub use evaluate::static_analysis;
pub use evaluate::DynamicContext;
pub use evaluate::evaluate;
pub use evaluate::Constructor;
pub use xslt::from_xnode;

Modules

evaluate

Evaluate a sequence constructor

item

xrust::item

xdmerror

xrust::error

xpath

xrust::xpath

xslt

An XSLT compiler