From 3931a44d500b440338796a1a29dc9f54cb134ffe Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 12 Apr 2022 20:11:39 +0200 Subject: [PATCH] minidom: enable support for writing rxml self-closing elements --- minidom/src/element.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 108ac2e..3c9b882 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -357,17 +357,19 @@ impl Element { encoder.encode(writer::Item::Attribute(None, name, value), buf)?; } - encoder.encode(writer::Item::ElementHeadEnd, buf)?; + if ! self.children.is_empty() { + encoder.encode(writer::Item::ElementHeadEnd, buf)?; - for child in &self.children { - match child { - Node::Text(s) => { - let text = CDataStr::from_str(s) - .map_err(::rxml::error::Error::NotWellFormed)?; - encoder.encode(writer::Item::Text(text), buf)?; + for child in &self.children { + match child { + Node::Text(s) => { + let text = CDataStr::from_str(s) + .map_err(::rxml::error::Error::NotWellFormed)?; + encoder.encode(writer::Item::Text(text), buf)?; + } + Node::Element(el) => + el.write_to_inner(encoder, buf)?, } - Node::Element(el) => - el.write_to_inner(encoder, buf)?, } }