Skip to content

Commit

Permalink
Merge pull request #8 from bugeats/fix-standalone
Browse files Browse the repository at this point in the history
Fix standalone attribute to render valid XML
  • Loading branch information
cocool97 committed Nov 5, 2022
2 parents 7dd697a + 643074c commit 11c88f7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ impl XML {
///
/// Consumes the XML object.
pub fn generate<W: Write>(self, mut writer: W) -> Result<()> {
let standalone_attribute = if let Some(standalone) = self.standalone {
format!(r#" standalone="{}""#, standalone.to_string())
} else {
String::default()
let standalone_attribute = match self.standalone {
Some(_) => r#" standalone="yes""#.to_string(),
None => String::default(),
};

writeln!(
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn test_complex_sorted_element_xml() {
let mut writer: Vec<u8> = Vec::new();
xml.generate(&mut writer).unwrap();

let expected = "<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"true\"?>
let expected = "<?xml version=\"1.1\" encoding=\"UTF-8\" standalone=\"yes\"?>
<house rooms=\"2\">
\t<room size=\"27\" city=\"Paris\" number=\"1\">This is room number 1</room>
\t<room city=\"LA\" number=\"2\" size=\"54\">This is room number 2</room>
Expand Down

0 comments on commit 11c88f7

Please sign in to comment.