pub struct Node<'a> { /* private fields */ }
Expand description
A single node of an HTML document. Nodes may be HTML elements, comments, or text nodes.
Implementations§
source§impl<'a> Node<'a>
impl<'a> Node<'a>
sourcepub fn new(document: &'a Document, index: usize) -> Option<Node<'a>>
pub fn new(document: &'a Document, index: usize) -> Option<Node<'a>>
Create a Node referring to the index
th Node of a document.
sourcepub fn name(&self) -> Option<&'a str>
pub fn name(&self) -> Option<&'a str>
Get the name of a Node if it is an HTML element, or None otherwise.
sourcepub fn attr(&self, name: &str) -> Option<&'a str>
pub fn attr(&self, name: &str) -> Option<&'a str>
Get the value of the attribute name
from a Node representing a HTML element.
sourcepub fn attrs(&self) -> impl Iterator<Item = (&'a str, &'a str)>
pub fn attrs(&self) -> impl Iterator<Item = (&'a str, &'a str)>
Get an iterator over the names and values of attributes of the Element. Returns an empty iterator for non Element nodes.
pub fn parent(&self) -> Option<Node<'a>>
pub fn prev(&self) -> Option<Node<'a>>
pub fn next(&self) -> Option<Node<'a>>
pub fn first_child(&self) -> Option<Node<'a>>
pub fn last_child(&self) -> Option<Node<'a>>
sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Get the combined textual content of a Node and all of its children.
sourcepub fn inner_html(&self) -> String
pub fn inner_html(&self) -> String
Serialize a Node’s children to an HTML string.
sourcepub fn find<P: Predicate>(&self, predicate: P) -> Find<'a, P> ⓘ
pub fn find<P: Predicate>(&self, predicate: P) -> Find<'a, P> ⓘ
Search for Nodes fulfilling predicate
in the descendants of a Node.
sourcepub fn as_text(&self) -> Option<&'a str>
pub fn as_text(&self) -> Option<&'a str>
Get the text of a text Node, or None if the node is not text.
sourcepub fn as_comment(&self) -> Option<&'a str>
pub fn as_comment(&self) -> Option<&'a str>
Get the text of a comment Node, or None if the node is not a comment.
sourcepub fn descendants(&self) -> Descendants<'a> ⓘ
pub fn descendants(&self) -> Descendants<'a> ⓘ
Construct an iterator over a Node’s descendant (transitive children) Nodes.