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
impl ElementNode
Sourcepub fn get_by_id(&self, id_value: &str) -> Option<&ElementNode>
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}
pub fn get_all_by_id(&self, id_value: &str) -> Vec<&ElementNode>
pub fn get_by_class(&self, value: &str) -> Option<&ElementNode>
pub fn get_all_by_class(&self, value: &str) -> Vec<&ElementNode>
pub fn get_by_tag_name(&self, tag_name: &str) -> Option<&ElementNode>
pub fn get_all_by_tag_name(&self, tag_name: &str) -> Vec<&ElementNode>
pub fn get_by_attr( &self, attributes_name: &str, attributes_value: &str, ) -> Option<&ElementNode>
pub fn get_all_by_attr( &self, attributes_name: &str, attributes_value: &str, ) -> Vec<&ElementNode>
Trait Implementations§
Source§impl Clone for ElementNode
impl Clone for ElementNode
Source§fn clone(&self) -> ElementNode
fn clone(&self) -> ElementNode
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ElementNode
impl Debug for ElementNode
Source§impl PartialEq for ElementNode
impl PartialEq for ElementNode
impl StructuralPartialEq for ElementNode
Auto Trait Implementations§
impl Freeze for ElementNode
impl RefUnwindSafe for ElementNode
impl Send for ElementNode
impl Sync for ElementNode
impl Unpin for ElementNode
impl UnwindSafe for ElementNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more