Crate rquery [] [src]

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

CompoundSelector

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.

UnexpectedTokenError

An error which is returned when parsing a selector encounters an unexpected token

Enums

DocumentError

The various errors that can happen when creating a document.

MatchType

The match type for an attribute selector.

Scope

The scope of the CompoundSelector.

SelectError

Errors which can be returned when performing a select operation.

Selector

The individual parts of the CompoundSelector. For example, the selector input[type="radio"] has two parts, the TagName and Attribute selectors.