You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Eric J. Peters" <ep...@rightrez.com> on 2003/12/05 12:58:04 UTC

Merging DOMDocuments.

 

Hi-

 

            I have 2 DOMDocuments, both of which were created by the
DOMBuilder.  I have several nodes in one of these documents that I would
like to add to a specific place in the other one.  However, everything I try
to do to accomplish this results in a DOMException: WRONG_DOCUMENT_ERR.

 

            Here is (roughly) my most recent attempt:

 

            DOMDocument *sourceDoc = parser->parse(.);

            DOMDocument *targetDoc = parser->parse(.);

 

            DOMNode *sourceLocation = sourceDoc->
getElementsByTagName(.)->item(0);

            DOMNode *targetLocation = targetDoc->
getElementsByTagName(.)->item(0);

 

            DOMNodeList *nodes = sourceLocation->getChildNodes();

 

            for(int i=0; i<nodes->getLength(); i++)

            {

                        DOMNode *node = nodes->item(i);

 

                        sourceLocation->removeChild(node);

                        targetLocation->appendChild(node);         // <--
throws WRONG_DOCUMENT_ERR

            }

 

            Any suggestions?

 

            Thanks,

            -Eric.