[][src]Struct htmldom_read::ChildrenFetch

pub struct ChildrenFetch<'a> { /* fields omitted */ }

Settings to fetch children nodes that apply to given criteria.

Examples

let html = r#"
<div id="mydiv">
    <p class="someclass">Text</p>
</div>
<a class="someclass else">link</a>
"#;

// Create node tree for HTML code.
let node = Node::from_html(html, &Default::default()).unwrap().unwrap();

// Create criteria. Find all `div` nodes with `id='mydiv'`.
let fetch = node.children_fetch()
        .tag("div")
        .key("id")
        .value("mydiv");

// Search for all children that apply to criteria.
let result = fetch.fetch();
// Returns the first node: `<div id='mydiv'>`.
assert_eq!(result.iter().nth(0).unwrap(), &node.children().get(0).unwrap());

// Search for all with class='someclass' allowing it to contain other classes too.
let fetch = node.children_fetch()
        .key("class")
        .value_part("someclass");
let result = fetch.fetch();
// Returns the nodes <p> and <a>.
assert_eq!(result.iter().nth(0).unwrap(),
        &node.children().get(0).unwrap().children().get(0).unwrap());
assert_eq!(result.iter().nth(1).unwrap(), &node.children().get(1).unwrap());

Methods

impl<'a> ChildrenFetch<'a>[src]

pub fn for_node(node: &'a Node) -> Self[src]

Get children fetcher for given node to find children that apply to some criteria.

pub fn same_for_node(&self, node: &'a Node) -> Self[src]

Clone the fetcher with already set criteria but for given different node.

pub fn tag(self, tag: &'a str) -> Self[src]

Tag to search for.

pub fn set_tag(&mut self, tag: &'a str)[src]

pub fn key(self, key: &'a str) -> Self[src]

Key to search for.

pub fn set_key(&mut self, key: &'a str)[src]

pub fn value(self, value: &'a str) -> Self[src]

Exact value to search for.

pub fn set_value(&mut self, value: &'a str)[src]

pub fn value_part(self, part: &'a str) -> Self[src]

If exact value is not set then this defines a part of the value separated with whitespaces to be found. If value is, however, set then this field is ignored entirely.

pub fn set_value_part(&mut self, part: &'a str)[src]

pub fn fetch(self) -> LinkedList<&'a NodeAccess>[src]

Get all children and their children that apply to the criteria. This function does not check the parent node!

Trait Implementations

impl<'a> Copy for ChildrenFetch<'a>[src]

impl<'a> Clone for ChildrenFetch<'a>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Debug for ChildrenFetch<'a>[src]

Auto Trait Implementations

impl<'a> Send for ChildrenFetch<'a>

impl<'a> Sync for ChildrenFetch<'a>

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.