diff -c dbxml-2.3.10-original/dbxml/src/dbxml/nodeStore/NsDom.cpp dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsDom.cpp *** dbxml-2.3.10-original/dbxml/src/dbxml/nodeStore/NsDom.cpp Tue Jan 9 15:29:19 2007 --- dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsDom.cpp Mon Oct 22 13:44:51 2007 *************** *** 529,545 **** if (prev) prev->nsMakeTransient(); - // Move text, if present. Just copy; explicit - // remove isn't required, as the node's going away - NsNode *node = child->getNsNode(); - if (node->hasLeadingText()) { - if (next) { - _coalesceTextNodes(child, next, false); - } else { - _coalesceTextNodes(child, this, true); - } - } - if (next) { next->setElemPrev(prev); if (prev) --- 529,534 ---- *************** *** 580,585 **** --- 569,585 ---- getNsDocument()->addToModifications( NodeModification::UPDATE, this); + // Move text, if present. Just copy; explicit + // remove isn't required, as the node's going away + NsNode *node = child->getNsNode(); + if (node->hasLeadingText()) { + if (next) { + _coalesceTextNodes(child, next, false); + } else { + _coalesceTextNodes(child, this, true); + } + } + // Remove the child from the tree child->_makeStandalone(); child->_parent = 0; *************** *** 638,644 **** int32_t index = -1; // -1 means append as last on list bool isChild = false; NsDomNav *prev = 0; ! // if no next, operation is appending child text if (!nextChild) { modified = this; --- 638,644 ---- int32_t index = -1; // -1 means append as last on list bool isChild = false; NsDomNav *prev = 0; ! NsDomNav *ttext = 0; // if no next, operation is appending child text if (!nextChild) { modified = this; *************** *** 662,667 **** --- 662,678 ---- nsNodeElement); modified = (NsDomElement*)nextChild; index = modified->getNsNode()->getNumLeadingText(); + NsNode *tnode = modified->getNsNode(); + if (tnode->hasTextChild()) { + // existing text on target will move "right." + // get first text child for renumbering, later + NsDomNav *last = modified->getNsLastChild(true); + while (last && last->getNsNodeType() == + nsNodeText) { + ttext = (NsDomText*)last; + last = last->getNsPrevSibling(); + } + } } } *************** *** 702,707 **** --- 713,730 ---- ((NsDomText*)next)->setIndex(newindex + 1); next = next->getNsNextSibling(); } + + // If modified == nextChild, we added leading text to + // an element; if it had child text, child text indexes + // must be renumbered + if (ttext) { // ttext set above + while (ttext && + (ttext->getNsNodeType() == nsNodeText)) { + int32_t newindex = ((NsDomText*)ttext)->getIndex(); + ((NsDomText*)ttext)->setIndex(newindex + 1); + ttext = ttext->getNsNextSibling(); + } + } getNsDocument()->addToModifications(NodeModification::UPDATE, modified); return child; *************** *** 976,982 **** { NsNode *tnode = target->getNsNode(); MemoryManager *mmgr = getMemoryManager(); ! // Cannot count on sibling links to the source. // They have been eliminated in the caller. // Instead use a counter. Previous sibling link --- 999,1014 ---- { NsNode *tnode = target->getNsNode(); MemoryManager *mmgr = getMemoryManager(); ! NsDomNav *ttext = 0; ! if (tnode->hasTextChild()) { ! // existing child text on target will move "right." ! // get first text child for renumbering, later ! NsDomNav *last = target->getNsLastChild(true); ! while (last && last->getNsNodeType() == nsNodeText) { ! ttext = (NsDomText*)last; ! last = last->getNsPrevSibling(); ! } ! } // Cannot count on sibling links to the source. // They have been eliminated in the caller. // Instead use a counter. Previous sibling link *************** *** 994,1001 **** int32_t index = 0; if (toChild) { index = tnode->getFirstTextChildIndex(); ! DBXML_ASSERT(index >= 0); } for (int i = 0; i < num; i++) { DBXML_ASSERT(first->getNsNodeType() == nsNodeText); if (nsTextType(first->getNsTextType()) == NS_PINST) { --- 1026,1034 ---- int32_t index = 0; if (toChild) { index = tnode->getFirstTextChildIndex(); ! if (index == -1) index = 0; } + for (int i = 0; i < num; i++) { DBXML_ASSERT(first->getNsNodeType() == nsNodeText); if (nsTextType(first->getNsTextType()) == NS_PINST) { *************** *** 1016,1028 **** } // caller has already rearranged sibling links correctly // need to renumber indexes on any remaining text siblings - // "first" is pointing to it, or it's pointing to the source node tmp = first; while (tmp && (tmp->getNsNodeType() == nsNodeText)) { int32_t newindex = ((NsDomText*)tmp)->getIndex(); ((NsDomText*)tmp)->setIndex(newindex + num); tmp = tmp->getNsNextSibling(); } } // --- 1049,1067 ---- } // caller has already rearranged sibling links correctly // need to renumber indexes on any remaining text siblings tmp = first; while (tmp && (tmp->getNsNodeType() == nsNodeText)) { int32_t newindex = ((NsDomText*)tmp)->getIndex(); ((NsDomText*)tmp)->setIndex(newindex + num); tmp = tmp->getNsNextSibling(); } + + // renumber child text nodes on target + while (ttext && (ttext->getNsNodeType() == nsNodeText)) { + int32_t newindex = ((NsDomText*)ttext)->getIndex(); + ((NsDomText*)ttext)->setIndex(newindex + num); + ttext = ttext->getNsNextSibling(); + } } // *************** *** 1527,1534 **** previous = newtext; if (returnLast) retval = newtext; // return last ! else if (i == startIndex) retval = newtext; } return retval; } --- 1566,1580 ---- previous = newtext; if (returnLast) retval = newtext; // return last ! else if (i == startIndex) { retval = newtext; + // first text child is first child only if + // no child elements + if (!_node->hasChildElem()) + _firstChild = newtext; + } + // child text is *always* last child + _lastChild = newtext; } return retval; } diff -c dbxml-2.3.10-original/dbxml/src/dbxml/nodeStore/NsNode.cpp dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsNode.cpp *** dbxml-2.3.10-original/dbxml/src/dbxml/nodeStore/NsNode.cpp Tue Jan 30 10:19:07 2007 --- dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsNode.cpp Mon Oct 22 12:18:49 2007 *************** *** 934,941 **** NsNode::clearPrev(XER_NS MemoryManager *mmgr) { nd_header.nh_flags &= ~NS_HASPREV; ! if (!noNav()) { ! DBXML_ASSERT(nd_nav); nd_nav->nn_prev.freeNid(mmgr); memset(&nd_nav->nn_prev, 0, sizeof(NsNid)); } --- 934,941 ---- NsNode::clearPrev(XER_NS MemoryManager *mmgr) { nd_header.nh_flags &= ~NS_HASPREV; ! if (!noNav() && nd_nav) { ! //DBXML_ASSERT(nd_nav); nd_nav->nn_prev.freeNid(mmgr); memset(&nd_nav->nn_prev, 0, sizeof(NsNid)); }