diff options
author | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-01-09 17:46:42 -0800 |
---|---|---|
committer | Arseny Kapoulkine <arseny.kapoulkine@gmail.com> | 2016-01-09 17:46:42 -0800 |
commit | df2a0ad28b24681fdc39275b5260132b0a3e6918 (patch) | |
tree | 41929fe4908d92bb1225dddd0e133e5b269e35d9 | |
parent | 85d8b225f2276333001dc0f96179bfef012277ae (diff) |
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.
-rw-r--r-- | src/pugixml.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
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; |