Skip to main content

NodeExt

Trait NodeExt 

Source
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§

Source

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.

Source

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.

Source

fn element_children(&self) -> Vec<NodeRef>

Collect the direct element children (skipping text and comment nodes) into a Vec.

Source

fn first_element_child(&self) -> Option<NodeRef>

Return the first direct child that is an element, or None.

Source

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.

Source

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.

Source

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).

Source

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.

Implementors§