diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 37b3f95..1c69481 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4064,6 +4064,7 @@ PUGI__NS_BEGIN PUGI__FN void node_output_attributes(xml_buffered_writer& writer, xml_node_struct* node, const char_t* indent, size_t indent_length, unsigned int flags, unsigned int depth) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); + const char_t enquotation_char = (flags & format_attribute_single_quote) ? '\'' : '"'; for (xml_attribute_struct* a = node->first_attribute; a; a = a->next_attribute) { @@ -4079,12 +4080,12 @@ PUGI__NS_BEGIN } writer.write_string(a->name ? a->name + 0 : default_name); - writer.write('=', '"'); + writer.write('=', enquotation_char); if (a->value) text_output(writer, a->value, ctx_special_attr, flags); - writer.write('"'); + writer.write(enquotation_char); } } diff --git a/src/pugixml.hpp b/src/pugixml.hpp index d01f15f..972f8a3 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -255,6 +255,9 @@ namespace pugi // Skip characters belonging to range [0; 32) instead of "&#xNN;" encoding. This flag is off by default. const unsigned int format_skip_control_chars = 0x100; + // Use single quotes ' instead of double quotes " for enclosing attribute values. This flag is off by default. + const unsigned int format_attribute_single_quote = 0x200; + // 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; diff --git a/tests/test_write.cpp b/tests/test_write.cpp index 9050807..3ffee68 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -632,7 +632,7 @@ TEST_XML(write_no_empty_element_tags, "textpremid<text&escapepostfin", parse_full) { - const unsigned int flagset[] = { format_indent, format_raw, format_no_declaration, format_indent_attributes, format_no_empty_element_tags }; + const unsigned int flagset[] = { format_indent, format_raw, format_no_declaration, format_indent_attributes, format_no_empty_element_tags, format_attribute_single_quote }; size_t flagcount = sizeof(flagset) / sizeof(flagset[0]); for (size_t i = 0; i < (size_t(1) << flagcount); ++i)