#xpath #xml #read #expressions #api #reader #queries

xpath_reader

Provides a convenient API to read from XML using XPath expressions

11 releases

Uses old Rust 2015

0.5.3 May 29, 2019
0.5.2 Mar 19, 2019
0.5.1 Nov 19, 2018
0.5.0 Apr 26, 2018
0.3.2 Jul 9, 2017

#2920 in Parser implementations

Download history 156/week @ 2023-11-27 169/week @ 2023-12-04 239/week @ 2023-12-11 206/week @ 2023-12-18 154/week @ 2023-12-25 183/week @ 2024-01-01 211/week @ 2024-01-08 230/week @ 2024-01-15 229/week @ 2024-01-22 239/week @ 2024-01-29 240/week @ 2024-02-05 224/week @ 2024-02-12 184/week @ 2024-02-19 53/week @ 2024-02-26 87/week @ 2024-03-04 32/week @ 2024-03-11

383 downloads per month
Used in 3 crates (2 directly)

Apache-2.0

26KB
460 lines

xpath_reader

xpath-reader Build Status

Provides a convenient API to read from XML using XPath expressions.

This crate is mostly a wrapper around the crate sxd_xpath.


lib.rs:

Provides a convenient API to read from XML using XPath expressions.

This crate is mostly a wrapper around the crate sxd_xpath.

Examples

use xpath_reader::{Context, Reader};

let xml = r#"<?xml version="1.0"?><book xmlns="books" name="Neuromancer" author="William Gibson"><tags><tag name="cyberpunk"/><tag name="sci-fi"/></tags></book>"#;

let mut context = Context::new();
context.set_namespace("b", "books");

let reader = Reader::from_str(xml, Some(&context)).unwrap();

let name: String = reader.read("//@name").unwrap();
assert_eq!(name, "Neuromancer".to_string());

let publisher: Option<String> = reader.read("//@publisher").unwrap();
let author: Option<String> = reader.read("//@author").unwrap();
assert_eq!(publisher, None);
assert_eq!(author, Some("William Gibson".to_string()));

let tags: Vec<String> = reader.read("//b:tags/b:tag/@name").unwrap();
assert_eq!(tags, vec!["cyberpunk".to_string(), "sci-fi".to_string()]);

Dependencies

~580KB
~14K SLoC