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§
Provided Methods§
Sourcefn is_document(&self) -> bool
fn is_document(&self) -> bool
Returns true
if node is of type Document
Sourcefn is_doctype(&self) -> bool
fn is_doctype(&self) -> bool
Returns true
if node is of type Doctype
Sourcefn is_comment(&self) -> bool
fn is_comment(&self) -> bool
Returns true
if node is of type Comment
Sourcefn is_processing_instruction(&self) -> bool
fn is_processing_instruction(&self) -> bool
Returns true
if node is of type ProcessingInstruction
Sourcefn is_element(&self) -> bool
fn is_element(&self) -> bool
Returns true
if node is of type Element
Sourcefn name(&self) -> &str
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]”
Sourcefn get(&self, attr: &str) -> Option<String>
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()));
Sourcefn text(&self) -> String
fn text(&self) -> String
Retrieves the text value of this element, as well as it’s child elements
Sourcefn parent(&self) -> Option<Handle>
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.