pub struct Node { /* private fields */ }
Expand description
Contains information about opening and corresponding closing tags. It also can contain the value of the text between opening and closing tags if there are no children. Otherwise, if there are children mixed with text then each text chunk is separated in it’s own node with other children in order they appear in the code.
Implementations§
Source§impl Node
impl Node
Sourcepub fn from_html(
html: &str,
settings: &LoadSettings,
) -> Result<Option<Node>, Error>
pub fn from_html( html: &str, settings: &LoadSettings, ) -> Result<Option<Node>, Error>
Load node tree from HTML string.
The root node has no start, end or text elements. It does have only children in it. When passing empty code, None will be returned. If there is an error parsing the HTML, then this function will fail and return the error type that occurred.
Sourcepub fn from_html_first(html: &str, settings: &LoadSettings) -> Option<Self>
pub fn from_html_first(html: &str, settings: &LoadSettings) -> Option<Self>
Load the first node from HTML string without wrapping node to the tree with root (empty first node). Just return the exact single node.
§Failures
None is returned if string does not contain any node (is empty).
Sourcepub fn start(&self) -> &Option<OpeningTag>
pub fn start(&self) -> &Option<OpeningTag>
Start tag information.
Sourcepub fn attributes(&self) -> Option<&Vec<Attribute>>
pub fn attributes(&self) -> Option<&Vec<Attribute>>
Start tag attributes.
Sourcepub fn attribute_by_name(&self, key: &str) -> Option<&Attribute>
pub fn attribute_by_name(&self, key: &str) -> Option<&Attribute>
Find attribute by it’s name.
Sourcepub fn put_attribute(&mut self, attr: Attribute) -> Result<(), Attribute>
pub fn put_attribute(&mut self, attr: Attribute) -> Result<(), Attribute>
Try saving given attribute in this node.
§Failure
If this attribute is already present then this function will not change it.
If you need to overwrite the attribute anyway use [overwrite_attribute
].
Sourcepub fn overwrite_attribute(&mut self, attr: Attribute)
pub fn overwrite_attribute(&mut self, attr: Attribute)
Save this attribute in the node. If it is already present then overwrite it.
Sourcepub fn children_fetch(&self) -> ChildrenFetch<'_>
pub fn children_fetch(&self) -> ChildrenFetch<'_>
Get children fetcher for this node to find children that apply to some criteria.
pub fn children_fetch_mut(&mut self) -> ChildrenFetchMut<'_>
Sourcepub fn change_name(&mut self, name: &str)
pub fn change_name(&mut self, name: &str)
Change name of opening and closing tags (if any).
Sourcepub fn change_opening_name(&mut self, name: &str)
pub fn change_opening_name(&mut self, name: &str)
Change the name of only opening tag if it exists.
Sourcepub fn change_closing_name(&mut self, name: &str)
pub fn change_closing_name(&mut self, name: &str)
Change the name of only closing tag if it exists.
Sourcepub fn children_mut(&mut self) -> &mut Children
pub fn children_mut(&mut self) -> &mut Children
Mutable access to array of node’s children.
Sourcepub fn clone_without_children(&self) -> Self
pub fn clone_without_children(&self) -> Self
Clone this node without cloning children leaving new node with empty children list.
Sourcepub fn wrap_to_root(self) -> Result<Self, Self>
pub fn wrap_to_root(self) -> Result<Self, Self>
Try wrapping this node into root. This makes it possible to use this node as individual tree.
It is required for trees to start with empty node only with children. Many functions rely on this rule. For example, Fetch functions filter data only in children ignoring parent attributes and data.
§Failures
If this node already is root it is returned back in Err.