diff --git a/src/xml/writer.rs b/src/xml/writer.rs index acc6d100..ecf7fd4b 100644 --- a/src/xml/writer.rs +++ b/src/xml/writer.rs @@ -1,7 +1,6 @@ use base64; use std::borrow::Cow; use std::io::Write; -use xml_rs::attribute::Attribute; use xml_rs::escape::escape_str_pcdata; use xml_rs::name::Name; use xml_rs::namespace::Namespace; @@ -86,6 +85,10 @@ impl EventWriter { fn maybe_end_plist(&mut self) -> Result<()> { // If there are no more open tags then write the element if self.stack.len() == 1 { + // We didn't tell the xml_writer about the tag so it thinks we're already at + // the root. As such, it's not going to prettify our output, so we need to include + // the newline ourselves. + self.xml_writer.write(WriteXmlEvent::Characters("\n"))?; self.end_element("plist")?; if let Some(Element::Root) = self.stack.pop() { } else { @@ -126,18 +129,10 @@ impl PlistEventWriter for EventWriter { // Write prologue let prologue = r#" + "#; self.xml_writer.write(WriteXmlEvent::Characters(prologue))?; - let version_name = Name::local("version"); - let version_attr = Attribute::new(version_name, "1.0"); - - self.xml_writer.write(WriteXmlEvent::StartElement { - name: Name::local("plist"), - attributes: Cow::Borrowed(&[version_attr]), - namespace: Cow::Borrowed(&self.empty_namespace), - })?; - self.stack.push(Element::Root); } } @@ -236,23 +231,23 @@ mod tests { let comparison = " -\t -\t\tAuthor -\t\tWilliam Shakespeare -\t\tLines -\t\t -\t\t\tIt is a tale told by an idiot, -\t\t\tFull of sound and fury, signifying nothing. -\t\t -\t\tDeath -\t\t1564 -\t\tHeight -\t\t1.6 -\t\tData -\t\tAAAAvgAAAAMAAAAeAAAA -\t\tBirthdate -\t\t1981-05-16T11:32:06Z -\t + +\tAuthor +\tWilliam Shakespeare +\tLines +\t +\t\tIt is a tale told by an idiot, +\t\tFull of sound and fury, signifying nothing. +\t +\tDeath +\t1564 +\tHeight +\t1.6 +\tData +\tAAAAvgAAAAMAAAAeAAAA +\tBirthdate +\t1981-05-16T11:32:06Z + "; let s = String::from_utf8(cursor.into_inner()).unwrap();