Struct ElementNode

Source
pub struct ElementNode {
    pub tag_name: String,
    pub attributes: Vec<(String, String)>,
    pub children: Vec<Node>,
}

Fields§

§tag_name: String§attributes: Vec<(String, String)>§children: Vec<Node>

Implementations§

Source§

impl ElementNode

Source

pub fn get_by_id(&self, id_value: &str) -> Option<&ElementNode>

Examples found in repository?
examples/example_1.rs (line 41)
7fn main() {
8    let html = r#"
9    <html lang="en">
10    <head>
11        <meta charset="UTF-8" />
12        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
13        <title>Document</title>
14    </head>
15    <body id="container">
16        ok ceci est un texte
17        <a href="2" id="l1">link1</a>
18        <a href="1">link2</a>
19        <form action="d" method="get">
20            <input type="text" name="name" />
21        </form>
22    </body>
23    </html>"#;
24
25    let mut lexer = Lexer::new(html);
26    let tokens = lexer.tokenize();
27
28    // for token in tokens.clone() {
29    //     println!("{:?}", token);
30    // }
31
32    let mut parser = Parser::new(tokens);
33    let parsed = parser.parse();
34
35    println!("{:#?}", parsed);
36
37    match DomTree::new::<Lexer, Parser>(html) {
38        Ok(dom) => {
39            if let Some(container) = dom.get_by_id("container") {
40                println!("Node id='container' {:?}", container);
41                if let Some(l1) = container.get_by_id("l1") {
42                    println!("Node id='l1' {:?}", l1);
43                }
44            } else {
45                println!("Id not found");
46            }
47        }
48        Err(e) => println!("Erreur de parsing : {:?}", e),
49    }
50}

Trait Implementations§

Source§

impl Debug for ElementNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ElementNode

Source§

fn eq(&self, other: &ElementNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ElementNode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.