Add format_no_empty_element_tags flag

Setting this flag outputs start and end tag for every element, including empty
elements.

Fixes #118.
This commit is contained in:
Arseny Kapoulkine 2016-11-09 09:11:30 -08:00
parent c75e3c45e5
commit cd7e0b04f6
2 changed files with 18 additions and 4 deletions

View File

@ -4077,6 +4077,16 @@ PUGI__NS_BEGIN
if (!node->value) if (!node->value)
{ {
if (!node->first_child) if (!node->first_child)
{
if (flags & format_no_empty_element_tags)
{
writer.write('>', '<', '/');
writer.write_string(name);
writer.write('>');
return false;
}
else
{ {
if ((flags & format_raw) == 0) if ((flags & format_raw) == 0)
writer.write(' '); writer.write(' ');
@ -4085,6 +4095,7 @@ PUGI__NS_BEGIN
return false; return false;
} }
}
else else
{ {
writer.write('>'); writer.write('>');

View File

@ -229,6 +229,9 @@ namespace pugi
// Write every attribute on a new line with appropriate indentation. This flag is off by default. // Write every attribute on a new line with appropriate indentation. This flag is off by default.
const unsigned int format_indent_attributes = 0x40; 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. // 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. // 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; const unsigned int format_default = format_indent;