use crate::{XMLVersion, XML};
pub struct XMLBuilder {
version: XMLVersion,
encoding: String,
standalone: Option<bool>,
indent: bool,
sort_attributes: bool,
}
impl Default for XMLBuilder {
fn default() -> Self {
Self {
version: XMLVersion::XML1_0,
encoding: "UTF-8".into(),
standalone: None,
indent: true,
sort_attributes: false,
}
}
}
impl XMLBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn version(mut self, version: XMLVersion) -> Self {
self.version = version;
self
}
pub fn encoding(mut self, encoding: String) -> Self {
self.encoding = encoding;
self
}
pub fn standalone(mut self, standalone: Option<bool>) -> Self {
self.standalone = standalone;
self
}
pub fn indent(mut self, indent: bool) -> Self {
self.indent = indent;
self
}
pub fn sort_attributes(mut self, sort: bool) -> Self {
self.sort_attributes = sort;
self
}
pub fn build(self) -> XML {
XML::new(
self.version,
self.encoding,
self.standalone,
self.indent,
self.sort_attributes,
)
}
}