You should read the DOM recommendation, or get a good book about the DOM.
You must use DOM_Document::importNode() to copy nodes from one instance to
another.
See:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#i-Document
You application is crashing because you're not catching DOM_Exception,
which is being thrown by ParentNode::insertBefore().
Dave
Rolf Jakob
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
nmail.com> cc: (bcc: David N Bertoni/CAM/Lotus)
Subject: copy nodes from one DOM to
another
07/16/2001 03:30
PM
Please respond to
xerces-c-dev
Hello,
For an XML editing application I would like to copy a node from one DOM to
another.
So I created two parsers and loaded each one with an XML file. The
application tries to insert a branch of nodes (one node with optional
children) from the second DOM tree into the first one.
Whether I use a validating parser or not does not seem to matter, it always
breaks on ParentNode::insertBefore() as shown in the following back trace
snippet :
#9 0x407b8fec in __terminate () from /usr/lib/libstdc++-libc6.1-2.so.3
#10 0x407b9a24 in throw_helper (eh=0x80defa8, pc=0x805797b,
my_udata=0xbffff054, offset_p=0xbffff050)
from /usr/lib/libstdc++-libc6.1-2.so.3
#11 0x407b9bdf in __throw () from /usr/lib/libstdc++-libc6.1-2.so.3
#12 0x401306ef in ParentNode::insertBefore ()
at
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/std/bastring.cc:177
#13 0x40129e8e in NodeImpl::appendChild ()
at
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/std/bastring.cc:177
#14 0x400de8c9 in DOM_Node::appendChild ()
at
/usr/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3/std/bastring.cc:177
What I try to do is :
- locate the position in the tree in the first DOM, select the appropriate
DOM_Node
- locate the DOM_Node to copy from in the second DOM and create a clone
using
DOM_Node::cloneNode(true) (just to be sure, I tried also w/o cloning)
- insert the cloned node (may have children) into the first DOM using
DOM_Node::appendChild() -- that's where the problem starts.
Accessing the nodes in question with getNodeName(), getNodeType(),
getFirstChild() etc. does not yield a problem so I could not find an
obvious
null pointer dereference.
Manupulating the DOM with appendChild with a node created by
DOM_Document::create{Element|TextNode|Comment} works fine.
Should it be possible to copy a node between DOMs, meaning I did something
wrong or is that not (yet) supposed to work ?
I use xerces-c 1.5.0, glibc 2.1.3, gcc 2.95.2 on Linux 2.4.5 - everything
compiled from source. I'm new to xerces so it's quite possible that I
overlooked something obvious.
All hints appreciated,
Rolf
---------------------------------------------------------------------
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]