Struct tl::VDom

source · []
pub struct VDom<'a> { /* private fields */ }
Expand description

VDom represents a Document Object Model

It is the result of parsing an HTML document. Internally it is only a wrapper around the Parser struct, in which all of the HTML tags are stored. Many functions of the public API take a reference to a Parser as a parameter to resolve NodeHandles to Nodes.

Implementations

Returns a reference to the underlying parser

Returns a mutable reference to the underlying parser

Finds an element by its id attribute.

Returns a list of elements that match a given class name.

Returns a slice of all the elements in the HTML document

The difference between children() and nodes() is that children only returns the immediate children of the root node, while nodes() returns all nodes, including nested tags.

Order

The order of the returned nodes is the same as the order of the nodes in the HTML document.

Returns a mutable slice of all the elements in the HTML document

The difference between children() and nodes() is that children only returns the immediate children of the root node, while nodes() returns all nodes, including nested tags.

Returns the topmost subnodes (“children”) of this DOM

Returns a mutable reference to the topmost subnodes (“children”) of this DOM

Returns the HTML version. This is determined by the <!DOCTYPE> tag

Returns the contained markup of all of the elements in this DOM.

Equivalent to Element#outerHTML in browsers)

Example
let html = r#"<div><p href="/about" id="find-me">Hello world</p></div>"#;
let mut dom = tl::parse(html, Default::default()).unwrap();

let element = dom.get_element_by_id("find-me")
    .unwrap()
    .get_mut(dom.parser_mut())
    .unwrap()
    .as_tag_mut()
    .unwrap();

element.attributes_mut().get_mut("href").flatten().unwrap().set("/");

assert_eq!(dom.outer_html(), r#"<div><p href="/" id="find-me">Hello world</p></div>"#);

Tries to parse the query selector and returns an iterator over elements that match the given query selector.

Example
let dom = tl::parse("<div><p class=\"foo\">bar</div>", tl::ParserOptions::default()).unwrap();
let handle = dom.query_selector("p.foo").and_then(|mut iter| iter.next()).unwrap();
let node = handle.get(dom.parser()).unwrap();
assert_eq!(node.inner_text(dom.parser()), "bar");

Trait Implementations

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Gets a node at a specific index

Gets or computes the length (number of nodes)

Gets the starting index

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.