pub trait NodeExt {
// Required methods
fn element_name(&self) -> Option<&str>;
fn attr_value(&self, name: &str) -> Option<String>;
fn element_children(&self) -> Vec<NodeRef>;
fn first_element_child(&self) -> Option<NodeRef>;
fn next_element_sibling(&self) -> Option<NodeRef>;
fn previous_element_sibling(&self) -> Option<NodeRef>;
fn inner_html(&self) -> String;
fn clone_and_rename_element(self, tag_name: &str) -> NodeRef;
}Expand description
DOM-navigation and element-manipulation helpers implemented on NodeRef.
This trait is automatically in scope when you import from
crate::parser or crate::shared_utils.
Required Methods§
Sourcefn element_name(&self) -> Option<&str>
fn element_name(&self) -> Option<&str>
Return the local tag name of this node if it is an element (e.g.
"div", "p"), or None for text / comment / document nodes.
Sourcefn attr_value(&self, name: &str) -> Option<String>
fn attr_value(&self, name: &str) -> Option<String>
Look up an attribute by name and return its value, or None if the
attribute is absent or this is not an element node.
Sourcefn element_children(&self) -> Vec<NodeRef>
fn element_children(&self) -> Vec<NodeRef>
Collect the direct element children (skipping text and comment nodes)
into a Vec.
Sourcefn first_element_child(&self) -> Option<NodeRef>
fn first_element_child(&self) -> Option<NodeRef>
Return the first direct child that is an element, or None.
Sourcefn next_element_sibling(&self) -> Option<NodeRef>
fn next_element_sibling(&self) -> Option<NodeRef>
Walk forward through siblings until an element node is found, or
return None if the end of the sibling list is reached.
Sourcefn previous_element_sibling(&self) -> Option<NodeRef>
fn previous_element_sibling(&self) -> Option<NodeRef>
Walk backward through siblings until an element node is found, or
return None if the beginning of the sibling list is reached.
Sourcefn inner_html(&self) -> String
fn inner_html(&self) -> String
Serialise the children of this node to an HTML string (the node’s own open/close tags are not included).
Sourcefn clone_and_rename_element(self, tag_name: &str) -> NodeRef
fn clone_and_rename_element(self, tag_name: &str) -> NodeRef
Create a new element with tag_name, copy all attributes and children
from self, splice the new node into the tree in self’s position,
and detach self. Returns the new node.
If self is not an element node it is returned unchanged.
When the source tag is one of the legacy size-attribute elements
(table, th, td, hr, pre) the width and height
attributes are stripped from the copy.