pub struct NodeRef<'a> { /* private fields */ }Expand description
A borrowed reference to a node inside the document.
Provides convenience methods for querying node properties, traversing the tree, and extracting content.
Implementations§
Source§impl<'a> NodeRef<'a>
impl<'a> NodeRef<'a>
Sourcepub fn is_comment(&self) -> bool
pub fn is_comment(&self) -> bool
Whether this is a comment node.
Sourcepub fn is_doctype(&self) -> bool
pub fn is_doctype(&self) -> bool
Whether this is a doctype node.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Whether this node has any children.
Sourcepub fn text(&self) -> &'a str
pub fn text(&self) -> &'a str
Direct text content of this node (not recursive).
For element nodes, returns "". For text nodes, returns the text.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Recursively collect all text content from this node and its descendants.
Sourcepub fn inner_html(&self) -> String
pub fn inner_html(&self) -> String
Reconstruct the inner HTML of this node.
Sourcepub fn outer_html(&self) -> String
pub fn outer_html(&self) -> String
Reconstruct the outer HTML of this node (including the tag itself).
Sourcepub fn has_class(&self, class_name: &str) -> bool
pub fn has_class(&self, class_name: &str) -> bool
Check if the node has a given CSS class.
Splits the class attribute on whitespace and checks if any
segment matches.
Sourcepub fn first_child(&self) -> Option<NodeRef<'a>>
pub fn first_child(&self) -> Option<NodeRef<'a>>
Get the first child, if any.
Sourcepub fn next_sibling(&self) -> Option<NodeRef<'a>>
pub fn next_sibling(&self) -> Option<NodeRef<'a>>
Get the next sibling, if any.
Sourcepub fn prev_sibling(&self) -> Option<NodeRef<'a>>
pub fn prev_sibling(&self) -> Option<NodeRef<'a>>
Get the previous sibling, if any.
Sourcepub fn ancestors(&self) -> Ancestors<'a> ⓘ
pub fn ancestors(&self) -> Ancestors<'a> ⓘ
Iterate over ancestors (parent chain, not including self).
Sourcepub fn descendants(&self) -> DepthFirst<'a> ⓘ
pub fn descendants(&self) -> DepthFirst<'a> ⓘ
Pre-order depth-first traversal of the subtree rooted at this node.
Sourcepub fn descendants_bfs(&self) -> BreadthFirst<'a> ⓘ
pub fn descendants_bfs(&self) -> BreadthFirst<'a> ⓘ
Breadth-first traversal of the subtree rooted at this node.