From df2a0ad28b24681fdc39275b5260132b0a3e6918 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 9 Jan 2016 17:46:42 -0800 Subject: Implement output support for embedded PCDATA values This is a bit awkward since preserving correct indentation structure requires a bit of extra work, and the closing tag has to be written by _start function to correctly process the rest of the tree. --- src/pugixml.cpp | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pugixml.cpp b/src/pugixml.cpp index c018359..90c677e 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4018,17 +4018,40 @@ PUGI__NS_BEGIN if (node->first_attribute) node_output_attributes(writer, node, indent, indent_length, flags, depth); - if (!node->first_child) + // element nodes can have value if parse_embed_pcdata was used + if (!node->value) { - writer.write(' ', '/', '>'); + if (!node->first_child) + { + writer.write(' ', '/', '>'); - return false; + return false; + } + else + { + writer.write('>'); + + return true; + } } else { writer.write('>'); - return true; + text_output(writer, node->value, ctx_special_pcdata, flags); + + if (!node->first_child) + { + writer.write('<', '/'); + writer.write_string(name); + writer.write('>'); + + return false; + } + else + { + return true; + } } } @@ -4136,6 +4159,10 @@ PUGI__NS_BEGIN if (node_output_start(writer, node, indent, indent_length, flags, depth)) { + // element nodes can have value if parse_embed_pcdata was used + if (node->value) + indent_flags = 0; + node = node->first_child; depth++; continue; -- cgit v1.2.3