From cd7e0b04f6851490c46d1a038764a9a7f44af232 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 9 Nov 2016 09:11:30 -0800 Subject: Add format_no_empty_element_tags flag Setting this flag outputs start and end tag for every element, including empty elements. Fixes #118. --- src/pugixml.cpp | 19 +++++++++++++++---- src/pugixml.hpp | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 7b96d34..dc3e7be 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4078,12 +4078,23 @@ PUGI__NS_BEGIN { if (!node->first_child) { - if ((flags & format_raw) == 0) - writer.write(' '); + if (flags & format_no_empty_element_tags) + { + writer.write('>', '<', '/'); + writer.write_string(name); + writer.write('>'); + + return false; + } + else + { + if ((flags & format_raw) == 0) + writer.write(' '); - writer.write('/', '>'); + writer.write('/', '>'); - return false; + return false; + } } else { diff --git a/src/pugixml.hpp b/src/pugixml.hpp index d9b9c86..6288d4b 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -229,6 +229,9 @@ namespace pugi // Write every attribute on a new line with appropriate indentation. This flag is off by default. const unsigned int format_indent_attributes = 0x40; + // Don't output empty element tags, instead writing an explicit start and end tag even if there are no children. This flag is off by default. + const unsigned int format_no_empty_element_tags = 0x80; + // The default set of formatting flags. // Nodes are indented depending on their depth in DOM tree, a default declaration is output if document has none. const unsigned int format_default = format_indent; -- cgit v1.2.3