parse_html/dom/
search.rs

1use crate::node::{ElementNode, Node};
2
3pub fn search_node_by_id<'a>(node: &'a Node, id_value: &str) -> Option<&'a ElementNode> {
4    if let Node::Element(element) = node {
5        for (attr_name, attr_value) in &element.attributes {
6            if attr_name == "id" && attr_value == id_value {
7                return Some(element);
8            }
9        }
10        for child in &element.children {
11            if let Some(found) = search_node_by_id(child, id_value) {
12                return Some(found);
13            }
14        }
15    }
16    None
17}