[−][src]Function xml5ever::interface::tree_builder::create_element
pub fn create_element<Sink>(
sink: &mut Sink,
name: QualName,
attrs: Vec<Attribute>
) -> <Sink as TreeSink>::Handle where
Sink: TreeSink,
A constructor for an element.
Examples
Create an element like <div class="test-class-name"></div>
:
use markup5ever::{rcdom, QualName, Attribute}; use markup5ever::interface::create_element; let mut dom = rcdom::RcDom::default(); let el = create_element(&mut dom, // Namespaces and localnames use precomputed interned strings for // speed. Use the macros ns! and local_name! to fetch them. QualName::new(None, ns!(), local_name!("div")), vec![ Attribute { name: QualName::new(None, ns!(), local_name!("class")), // In real scenarios, you would use a view onto an existing // string if possible to avoid allocation. Tendrils have utilities // for avoiding allocation & copying wherever possible. value: String::from("test-class-name").into() } ]);