pub struct Document {
pub arena: NodeArena,
pub root: NodeId,
}Expand description
The DOM Document
Fields§
§arena: NodeArena§root: NodeIdImplementations§
Source§impl Document
impl Document
Sourcepub fn create_element(&mut self, tag_name: &str) -> NodeId
pub fn create_element(&mut self, tag_name: &str) -> NodeId
Create an element node
Sourcepub fn create_element_with_attrs(
&mut self,
tag_name: &str,
attrs: BTreeMap<String, String>,
) -> NodeId
pub fn create_element_with_attrs( &mut self, tag_name: &str, attrs: BTreeMap<String, String>, ) -> NodeId
Create an element node with attributes
Sourcepub fn create_text(&mut self, text: &str) -> NodeId
pub fn create_text(&mut self, text: &str) -> NodeId
Create a text node
Sourcepub fn create_comment(&mut self, text: &str) -> NodeId
pub fn create_comment(&mut self, text: &str) -> NodeId
Create a comment node
Sourcepub fn create_doctype(&mut self, name: &str) -> NodeId
pub fn create_doctype(&mut self, name: &str) -> NodeId
Create a document type node
Sourcepub fn append_child(&mut self, parent_id: NodeId, child_id: NodeId)
pub fn append_child(&mut self, parent_id: NodeId, child_id: NodeId)
Append a child node to a parent
Sourcepub fn remove_child(&mut self, parent_id: NodeId, child_id: NodeId)
pub fn remove_child(&mut self, parent_id: NodeId, child_id: NodeId)
Remove a child from its parent
Sourcepub fn insert_before(
&mut self,
parent_id: NodeId,
new_child_id: NodeId,
ref_child_id: NodeId,
)
pub fn insert_before( &mut self, parent_id: NodeId, new_child_id: NodeId, ref_child_id: NodeId, )
Insert a child before a reference node
Sourcepub fn get_element_by_id(&self, id: &str) -> Option<NodeId>
pub fn get_element_by_id(&self, id: &str) -> Option<NodeId>
Find an element by its “id” attribute
Sourcepub fn get_elements_by_tag_name(&self, tag: &str) -> Vec<NodeId>
pub fn get_elements_by_tag_name(&self, tag: &str) -> Vec<NodeId>
Find all elements with a given tag name
Sourcepub fn walk<F: FnMut(NodeId)>(&self, start: NodeId, callback: &mut F)
pub fn walk<F: FnMut(NodeId)>(&self, start: NodeId, callback: &mut F)
Walk the tree depth-first, calling the callback on each node
Sourcepub fn descendants(&self, start: NodeId) -> Vec<NodeId>
pub fn descendants(&self, start: NodeId) -> Vec<NodeId>
Get all descendant NodeIds (depth-first)
Sourcepub fn ancestors(&self, start: NodeId) -> Vec<NodeId>
pub fn ancestors(&self, start: NodeId) -> Vec<NodeId>
Get all ancestor NodeIds (from parent up to root)
Sourcepub fn inner_text(&self, node_id: NodeId) -> String
pub fn inner_text(&self, node_id: NodeId) -> String
Get the inner text of a node (concatenation of all text descendants)
Sourcepub fn outer_html(&self, node_id: NodeId) -> String
pub fn outer_html(&self, node_id: NodeId) -> String
Generate outer HTML for debugging
Sourcepub fn get_attribute(&self, node_id: NodeId, attr: &str) -> Option<String>
pub fn get_attribute(&self, node_id: NodeId, attr: &str) -> Option<String>
Get an attribute value from an element node
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Count total nodes in the arena