Title: Message
See DOMDocument::importNode().
-----Original Message-----
From: Eric J. Peters [mailto:[EMAIL PROTECTED]
Sent: Friday, December 05, 2003 6:58 AM
To: Xerces Mailing List
Subject: 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.

 

Reply via email to