0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-27 13:33:17 +08:00

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.
This commit is contained in:
Arseny Kapoulkine 2016-01-12 20:01:44 -08:00
parent df2a0ad28b
commit bcddf36559

View File

@ -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);