Function sxd_xpath::evaluate_xpath [] [src]

pub fn evaluate_xpath<'d>(
    document: &'d Document<'d>,
    xpath: &str
) -> Result<Value<'d>, Error>

Easily evaluate an XPath expression

The core XPath 1.0 functions will be available, and no variables or namespaces will be defined. The root of the document is the context node.

If you will be evaluating multiple XPaths or the same XPath multiple times, this may not be the most performant solution.

Examples

extern crate sxd_document;
extern crate sxd_xpath;

use sxd_document::parser;
use sxd_xpath::{evaluate_xpath, Value};

fn main() {
    let package = parser::parse("<root><a>1</a><b>2</b></root>").expect("failed to parse the XML");
    let document = package.as_document();

    assert_eq!(Ok(Value::Number(3.0)), evaluate_xpath(&document, "/*/a + /*/b"));
}