DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Child removal problem with Xerces (http://www.daniweb.com/forums/thread181999.html)

GDICommander Mar 17th, 2009 10:05 am
Child removal problem with Xerces
 
I need help with the code below. At root->removeChild(nodeToRemove), I have a NOT_FOUND_ERR code. It is not supposed to return this code, because I look in the DOM Tree with IsInDocument.

Can someone tell me what's wrong with this code. I'm becoming blind with this code.

DOMNode* nodeToRemove;
if ((nodeToRemove = IsInDocument(root, *it)) != 0)
{
        if (nodeToRemove->isEqualNode(root))
        {
                root = 0;
                break;
        }
        root->removeChild(nodeToRemove);
}
DOMNode* IsInDocument(DOMNode* node, DOMNode* toFind)
{
        if (node->isEqualNode(toFind))
        {
                return node;
        }
        else
        {
                node = node->getFirstChild();
                while (node != 0)
                {
                        DOMNode* retval;
                        if ((retval = IsInDocument(node, toFind)) != 0)
                        {
                                return retval;
                        }
                        node = node->getNextSibling();                               
                }
               
                return 0;
        }
}

When I debug, this is where an exception is thrown.

    if (castToNodeImpl(this)->isReadOnly())
        throw DOMException(
        DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMParentNodeMemoryManager);

    if (oldChild == 0 || oldChild->getParentNode() != castToNode(this))
        throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMParentNodeMemoryManager);

    if (this->getOwnerDocument() !=  0  ) {
        //notify iterators
        NodeIterators* nodeIterators = ((DOMDocumentImpl *)this->getOwnerDocument())->getNodeIterators();
        if (nodeIterators != 0) {
            XMLSize_t sz = nodeIterators->size();
            if (sz != 0) {
                for (XMLSize_t i =0; i<sz; i++) {
                    if (nodeIterators->elementAt(i) != 0)
                        nodeIterators->elementAt(i)->removeNode(oldChild);
                }
            }
        }

GDICommander Mar 17th, 2009 10:50 am
Re: Child removal problem with Xerces
 
Ok, I have found the error. removeChild is not a recursive function. Sorry for this self-solved thread.


All times are GMT -4. The time now is 4:13 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC