Hi Joerg,
the exception you are getting is probably WRONG_DOCUMENT_ERR (hint:
add a try/catch(DOMException&) to your code); from the doc
(http://xml.apache.org/xerces-c/apiDocs/classDOMNode.html#z229_15)
you can see that it is "raised if newChild was created from a
different document than the one that created this node". In this case
you first need to "import" such node into the new DOMDocument using
DOMDocument::importNode
(http://xml.apache.org/xerces-c/apiDocs/classDOMDocument.html#z59_0),
then use appendChild on the newly created clone of the original node
Alberto
At 13.04 20/12/2006 +0100, Joerg Toellner wrote:
Dear Xerces-Group,
Xerces-C 2.7, WinXP, MSVC2005 Pro
I fiddle now for more than a day with the following problem that i can't
solve myself even with reading the manual, searching the web a.s.o.
I have two xml documents. I load and parse both. Then i want to transfer
some nodes that i get with GetElementsByTagName in a DOMNodeList from the
first document and append them (merge them in, after a specific node) in the
second document.
All works fine. The documents load and are parsed correctly. I got the
NodeList with the correct getLength() and i get the parent node from the
second document to which i want to appendChild() the nodes in the list.
But within the line where i appendChild() (see the line marked with "Line B"
in the following code snippet) i get an exception and i can't figure out
why.
If i try to append a "fresh" created node (not one got from my file1) it
works like charm. See the commented out line marked "Line A" in the
following code snippet.
What do i wrong? Even tried to removeNode() the node to be transfered
instead of cloneNode(). But with the same effect.
If you need more information (e.g. Sample XML-Files, more Code, have some
questions a.s.o.) please ask for it. I'll send and reply asap.
Every hint appreciated. Many thanks in advance for your effort and help.
And merry christmas to all Xerces'ies! :-)
Greetings
Joerg
-------------------------------------------
Here is my code snippet:
int dmpmainFrame::AppendKVSTFile(DOMDocument *astdoc)
{
DOMDocument *kvsdoc;
DOMBuilder *builder;
DOMNodeList *kvsdnl;
DOMElement *aktast, *aktkvs;
int anzkvs, x, status;
// initialise Variables
status = TRUE;
// get a DOMBuilder from the already initialised DOMImplementation
builder = ((DOMImplementationLS*) m_DOMImpl)->
createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
// Load and parse File 2
// (File 1 comes via function parameter and is already loaded and
parsed)
kvsdoc = dom_ParseDoc((char *) m_DmpKvstFile.c_str(), builder);
if(!kvsdoc)
{
status = FALSE;
goto dmpMainFrame_AppendKVSTFile_Ende;
}
// Find both relevant parent nodes
aktast = (DOMElement *) dom_GetNodeByPath(astdoc->getDocumentElement(),
"datenannahmestellen_liste");
aktkvs = (DOMElement *) dom_GetNodeByPath(kvsdoc->getDocumentElement(),
"datenannahmestellen_liste");
if(!aktast || !aktkvs)
{
status = FALSE;
goto dmpMainFrame_AppendKVSTFile_Ende;
}
// get a DOMNodeList for all the Elements we need to copy
kvsdnl = aktkvs->getElementsByTagName(X("intended_recipient"));
if(!kvsdnl)
{
status = FALSE;
goto dmpMainFrame_AppendKVSTFile_Ende;
}
anzkvs = kvsdnl->getLength();
// Loop through all elements in the gotten list
for(x = 0; x < anzkvs; x++)
{
DOMElement *nd = (DOMElement *) kvsdnl->item(x)->cloneNode(TRUE);
//nd = astdoc->createElement(X("test")); /***** Line A *****/
aktast->appendChild(nd); /***** Line B *****/
}
// Cleanup and Exit
dmpMainFrame_AppendKVSTFile_Ende:
if(builder)
builder->release();
return status;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]