parse_html/
node.rs

1use crate::dom::search::search_node_by_id;
2
3#[derive(Debug, PartialEq)]
4pub enum Node {
5    Element(ElementNode),
6    Text(String),
7}
8
9#[derive(Debug, PartialEq)]
10pub struct ElementNode {
11    pub tag_name: String,
12    pub attributes: Vec<(String, String)>,
13    pub children: Vec<Node>,
14}
15
16impl ElementNode {
17    pub fn get_by_id(&self, id_value: &str) -> Option<&ElementNode> {
18        for node in &self.children {
19            if let Some(found) = search_node_by_id(node, id_value) {
20                return Some(found);
21            }
22        }
23        None
24    }
25}