Expand description
This library offers the ability to represent XML documents as DOM trees, allowing querying with CSS selectors.
extern crate rquery;
use rquery::Document;
fn main() {
let document = Document::new_from_xml_file("tests/fixtures/sample.xml").unwrap();
let title = document.select("title").unwrap();
assert_eq!(title.text(), "Sample Document");
assert_eq!(title.attr("ref").unwrap(), "main-title");
let item_count = document.select_all("item").unwrap().count();
assert_eq!(item_count, 2);
let item_titles = document.select_all("item > title").unwrap()
.map(|element| element.text().clone())
.collect::<Vec<String>>()
.join(", ");
assert_eq!(item_titles, "Another Sample, Other Sample");
}
Structs§
- Compound
Selector - Represents a component of a parsed CSS selector is used to match a single element.
- Document
- The DOM tree representation of the parsed document.
- Element
- Represents a single element in the DOM tree.
- Unexpected
Token Error - An error which is returned when parsing a selector encounters an unexpected token
Enums§
- Document
Error - The various errors that can happen when creating a document.
- Match
Type - The match type for an attribute selector.
- Scope
- The scope of the
CompoundSelector
. - Select
Error - Errors which can be returned when performing a select operation.
- Selector
- The individual parts of the
CompoundSelector
. For example, the selectorinput[type="radio"]
has two parts, theTagName
andAttribute
selectors.