summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-01-12 20:01:44 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2016-01-12 20:01:44 -0800
commitbcddf36559c4293d34fd275a4d392982fae94998 (patch)
treefe483fd31d6bddec9ce68f1baa62332752d22744 /src
parentdf2a0ad28b24681fdc39275b5260132b0a3e6918 (diff)
Only save first PCDATA contents in the element
This change fixes an important ordering issue - if element node has a PCDATA child *after* other elements, it's impossible to tell which order the children were in. Since the goal of PCDATA embedding is to save memory when it's the only child, only apply the optimization to the first child. This seems to fix all roundtripping issues so the only caveat is that the DOM structure is different.
Diffstat (limited to 'src')
-rw-r--r--src/pugixml.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index 90c677e..f447e97 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3360,7 +3360,11 @@ PUGI__NS_BEGIN
if (cursor->parent || PUGI__OPTSET(parse_fragment))
{
- if (!PUGI__OPTSET(parse_embed_pcdata))
+ if (PUGI__OPTSET(parse_embed_pcdata) && cursor->parent && !cursor->first_child && !cursor->value)
+ {
+ cursor->value = s; // Save the offset.
+ }
+ else
{
PUGI__PUSHNODE(node_pcdata); // Append a new node on the tree.
@@ -3368,11 +3372,6 @@ PUGI__NS_BEGIN
PUGI__POPNODE(); // Pop since this is a standalone.
}
- else
- {
- if (cursor->parent && !cursor->value)
- cursor->value = s; // Save the offset.
- }
s = strconv_pcdata(s);