pub struct ElementBuilder<'a> { /* private fields */ }
Expand description
An easy way to build a new element by chaining methods to add properties.
Call Element::build()
to start building.
To finish building, either call .finish()
or .push_to(parent)
which returns Element
.
§Examples
use xml_doc::{Document, Element, Node};
let mut doc = Document::new();
let root = Element::build(&mut doc, "root")
.attribute("id", "main")
.attribute("class", "main")
.finish();
doc.push_root_node(root.as_node());
let name = Element::build(&mut doc, "name")
.text_content("No Name")
.push_to(root);
/* Equivalent xml:
<root id="main" class="main">
<name>No Name</name>
</root>
*/
Implementations§
Source§impl<'a> ElementBuilder<'a>
impl<'a> ElementBuilder<'a>
Sourcepub fn prefix<S: Into<String>>(self, prefix: S) -> Self
pub fn prefix<S: Into<String>>(self, prefix: S) -> Self
Removes previous prefix if it exists, and attach new prefix.
pub fn attribute<S, T>(self, name: S, value: T) -> Self
pub fn namespace_decl<S, T>(self, prefix: S, namespace: T) -> Self
pub fn text_content<S: Into<String>>(self, text: S) -> Self
pub fn finish(self) -> Element
Auto Trait Implementations§
impl<'a> Freeze for ElementBuilder<'a>
impl<'a> RefUnwindSafe for ElementBuilder<'a>
impl<'a> Send for ElementBuilder<'a>
impl<'a> Sync for ElementBuilder<'a>
impl<'a> Unpin for ElementBuilder<'a>
impl<'a> !UnwindSafe for ElementBuilder<'a>
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