pub struct Node { /* private fields */ }Expand description
A mutable struct composed of a tag, attribute list, child list and closing type.
Do not attempt to modify the Node element directly. Use the available methods.
Node {
tag: String,
attributes: Option<Vec<String>>,
children: Option<Vec<Children>>,
closing_type: Closing
}Implementations§
Source§impl Node
impl Node
Sourcepub fn set_attribute(&mut self, name: &str, value: &str)
pub fn set_attribute(&mut self, name: &str, value: &str)
Sets the value of the Node’s attribute. This does not return an error if the wrong (key, value) was set.
§Example
use aurochs::Document;
let mut html = Document::create_element("html");
html.set_attribute("lang", "en");§Javascript Equivalent
let html = document.createElement("html");
html.setAttribute("lang", "en");§HTML
<html lang="en"></html>Sourcepub fn set_attribute_list(&mut self, attributes: Vec<(&str, &str)>)
pub fn set_attribute_list(&mut self, attributes: Vec<(&str, &str)>)
Sets the values of the Node’s attributes. This does not return an error if the wrong (key, value) was set.
§Example
use aurochs::Document;
let mut script = Document::create_element("script");
script.set_attribute_list(vec![("src", "./main.js"), ("defer", ""), ("type", "module")]);§Javascript Equivalent
let script = document.createElement("script");
const attributes = { "src": "./main.js", "defer": "", "type": "module" };
for (let key in attributes ) {
script.setAttribute(key, attributes[key]);
}§HTML
<script src="./main.js" defer type="module"></script>Sourcepub fn inner_text(&mut self, value: &str)
pub fn inner_text(&mut self, value: &str)
Sourcepub fn append_child(&mut self, node: Node)
pub fn append_child(&mut self, node: Node)
Adds a Node to the end of the list of children of a specified parent Node.
§Example
use aurochs::Document;
let mut body = Document::create_element("body");
let mut paragraph = Document::create_element("p");
body.append_child(paragraph);§Javascript Equivalent
let body = document.createElement("body");
let paragraph = document.createElement("p");
body.appendChild(paragraph);§HTML
<body>
<p><p>
</body>Sourcepub fn append_child_list(&mut self, children: Vec<Node>)
pub fn append_child_list(&mut self, children: Vec<Node>)
Adds multiple Nodes to the end of the list of children of a specified parent Node.
§Example
use aurochs::Document;
let mut body = Document::create_element("body");
let mut h1 = Document::create_element("h1");
let mut h2 = Document::create_element("h2");
let mut h3 = Document::create_element("h3");
body.append_child_list(vec![ h1, h2, h3 ]);§Javascript Equivalent
let body = document.createElement("body");
let h1 = document.createElement("h1");
let h2 = document.createElement("h2");
let h3 = document.createElement("h3");
const elements = { h1, h2, h3 };
for (let elem in elements) {
body.appendChild(elements[elem]);
}§HTML
<body>
<h1><h1>
<h2><h2>
<h3><h3>
</body>Sourcepub fn clone_node(&self) -> Node
pub fn clone_node(&self) -> Node
Returns a duplicate of the Node on which this method was called. Cloning a Node copies all of its attributes and their values, including intrinsic (inline) listeners.
Warning: clone_node() may lead to duplicate Node attributes in a document, such as IDs and CLASSes!
§Example
use aurochs::Document;
let mut paragraph = Document::create_element("p");
let mut paragraph_clone = paragraph.clone_node();§Javascript Equivalent
let paragraph = document.createElement("p");
let paragraph_clone = paragraph.cloneNode(true);§HTML
<p><p>
<p><p>Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Returns the parsed Node Tree as a string
§Example
use aurochs::Document;
let mut html = Document::create_element("html");
html.set_attribute("lang", "en");
let mut head = Document::create_element("head");
let mut body = Document::create_element("body");
html.append_child_list(vec![ head, body]);
println!("{}", html.render());§HTML
<html lang="en">
<head></head>
<body></body>
</html>