Trait NodeExt

Source
pub trait NodeExt: Sized {
Show 13 methods // Required method fn get_node(&self) -> &Node; // Provided methods fn is_document(&self) -> bool { ... } fn is_doctype(&self) -> bool { ... } fn is_text(&self) -> bool { ... } fn is_comment(&self) -> bool { ... } fn is_processing_instruction(&self) -> bool { ... } fn is_element(&self) -> bool { ... } fn name(&self) -> &str { ... } fn get(&self, attr: &str) -> Option<String> { ... } fn attrs(&self) -> BTreeMap<String, String> { ... } fn text(&self) -> String { ... } fn display(&self) -> String { ... } fn parent(&self) -> Option<Handle> { ... }
}
Expand description

Adds some convenience methods to the html5ever::rcdom::Node type

Required Methods§

Source

fn get_node(&self) -> &Node

Retrieves the node that these methods will work on

Provided Methods§

Source

fn is_document(&self) -> bool

Returns true if node is of type Document

Source

fn is_doctype(&self) -> bool

Returns true if node is of type Doctype

Source

fn is_text(&self) -> bool

Returns true if node is of type Text

Source

fn is_comment(&self) -> bool

Returns true if node is of type Comment

Source

fn is_processing_instruction(&self) -> bool

Returns true if node is of type ProcessingInstruction

Source

fn is_element(&self) -> bool

Returns true if node is of type Element

Source

fn name(&self) -> &str

Retrieves the name of the node

If this node is an element, the name of that element is returned. Otherwise, special names are used:

  • Document -> “[document]”
  • Doctype -> “[doctype]”
  • Text -> “[text]”
  • Comment -> “[comment]”
  • ProcessingInstruction -> “[processing-instruction]”
Source

fn get(&self, attr: &str) -> Option<String>

Looks for an attribute named attr and returns it’s value as a string

§Example
let soup = Soup::new(r#"<div class="foo bar"></div>"#);
let div = soup.tag("div").find().expect("Couldn't find div");
assert_eq!(div.get("class"), Some("foo bar".to_string()));
Source

fn attrs(&self) -> BTreeMap<String, String>

Returns the node’s attributes as a BTreeMap

Source

fn text(&self) -> String

Retrieves the text value of this element, as well as it’s child elements

Source

fn display(&self) -> String

Returns the node as an html tag

Source

fn parent(&self) -> Option<Handle>

Navigates to the parent of the node, if there is one

§Example
extern crate soup;

use soup::prelude::*;
let soup = Soup::new(r#"<div id=""><b>FOO</b></div>"#);
let b = soup.tag("b").find().expect("Couldn't find tag 'b'");
let div = b.parent().expect("Couldn't get parent of tag 'b'");
assert_eq!(div.name(), "div".to_string());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl NodeExt for Handle

Source§

fn get_node(&self) -> &Node

Source§

impl<'node> NodeExt for &'node Node

Source§

fn get_node(&self) -> &Node

Implementors§