2019-11-05 11:03:23 +02:00
|
|
|
use super::XMLBuilder;
|
|
|
|
|
|
|
|
impl XMLBuilder {
|
|
|
|
// Build XML declaration
|
|
|
|
// i.e. <?xml version="1.0" encoding="UTF-8"?>
|
2019-11-05 12:20:40 +02:00
|
|
|
pub(crate) fn declaration(mut self, standalone: Option<bool>) -> Self {
|
2019-11-05 11:03:23 +02:00
|
|
|
self.writer
|
|
|
|
.write(super::XmlEvent::StartDocument {
|
|
|
|
version: super::XmlVersion::Version10,
|
|
|
|
encoding: Some("UTF-8"),
|
2019-11-05 12:20:40 +02:00
|
|
|
standalone,
|
2019-11-05 11:03:23 +02:00
|
|
|
})
|
|
|
|
.expect("should write to buf");
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_declaration() {
|
|
|
|
let b = XMLBuilder::new();
|
2019-11-05 12:20:40 +02:00
|
|
|
let r = b.declaration(None).build();
|
2019-11-05 11:03:23 +02:00
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&r).unwrap(),
|
|
|
|
r#"<?xml version="1.0" encoding="UTF-8"?>"#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|