Expand description
§Examples
To load nodes from HTML.
let html = r#"
<div><p>Text</p></div>
"#;
// Load with default settings.
let nodes = Node::from_html(html, &Default::default()).unwrap().unwrap();
let first_node = nodes.children().get(0).unwrap();
// First node is <div>
assert_eq!("div", first_node.tag_name().unwrap());
let children = first_node.children();
// First child of <div> is <p>
let first_child = children.get(0).unwrap();
assert_eq!("p", first_child.tag_name().unwrap());
/// The child of <p> is Text
assert_eq!("Text", first_child.children().get(0).unwrap().text().unwrap());
Load node with text mixed with children. Text that is not mixed load inside the parent node and not as separate child.
let html = r#"
<p>Text <sup>child</sup> more text</p>
"#;
let settings = LoadSettings::new().all_text_separately(false);
let from = Node::from_html(html, &settings).unwrap().unwrap();
let node = from.children().get(0).unwrap();
let children = node.children();
let first_text = children.get(0).unwrap();
assert_eq!("Text ", first_text.text().unwrap());
let sup = children.get(1).unwrap();
assert_eq!("child", sup.text().unwrap());
let last_text = children.get(2).unwrap();
assert_eq!(" more text", last_text.text().unwrap());
Structs§
- Attribute
- Attribute of the tag.
- Children
- Children of the node. All tags that are inside of parent node are listed in this struct.
- Children
Fetch - Settings to fetch children nodes that apply to given criteria.
- Children
Fetch Mut - Mutable
ChildrenFetch
. Allows to get mutable access to returned nodes. - Load
Settings - Settings that provide different options of how to parse HTML.
- Node
- Contains information about opening and corresponding closing tags. It also can contain the value of the text between opening and closing tags if there are no children. Otherwise, if there are children mixed with text then each text chunk is separated in it’s own node with other children in order they appear in the code.
- Opening
Tag - Information carried in the opening tag.
Enums§
- Children
Type - How children are stored in the node.
- Node
Access - How node is being stored and accessed.