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 Ian Sweeny <Ia...@creaturelabs.com> on 2001/02/13 18:46:58 UTC
importNode()
Has anyone got any example code that successfully implements
DOM_Document::importNode( )?
Here's what I'm trying to do at the moment:
DOM_Node import_node = sourceNode.getFirstChild();
DOM_Node temp_node = doc.importNode(import_node, true);
myDOMNode.appendChild(temp_node);
myDOMNode if the root node of the DOM tree I wish to import into.
doc is my DOM_Document that I wish to import into.
sourceNode is the root node of the source tree I wish to import.
Without doing getFirstChild( ) on the source tree, so I get the first
element in the tree,
importNode( ) fails at runtime.
But now appendChild( ) fails when I try to append the new tree to my
existing tree.
Any ideas, I'm new to this Xerces stuff.
Thanks in advance,
Ian.
Re: importNode()
Posted by Miroslaw Dobrzanski-Neumann <mn...@mosaic-ag.com>.
On Tue, Feb 13, 2001 at 05:46:58PM -0000, Ian Sweeny wrote:
>
> Has anyone got any example code that successfully implements
> DOM_Document::importNode( )?
...
if (_doc == source->_doc)
clone = toclone.cloneNode(true);
else
clone = _doc.importNode(toclone, true);
if (isroot)
copyElementContent(torepl, clone, true);
else
parent.replaceChild(clone, torepl);
...
void MYXML_DocumentImpl::copyElementContent(DOM_Node dst, DOM_Node src, bool clear)
{
DOM_NamedNodeMap dstattr = dst.getAttributes();
if (clear) {
for (DOM_Node clr = dst.getFirstChild(); !clr.isNull(); clr = dst.getFirstChild())
dst.removeChild(clr);
size_t upto = dstattr.getLength();
for (size_t idx = 0; idx < upto; idx++) {
DOM_Node n = dstattr.item(0);
dstattr.removeNamedItem(n.getNodeName());
}
}
for (DOM_Node cld = src.getFirstChild(); !cld.isNull(); cld = src.getFirstChild())
dst.appendChild(cld);
DOM_NamedNodeMap srcattr = src.getAttributes();
size_t upto = srcattr.getLength();
for (size_t idx = 0; idx < upto; idx++) {
DOM_Node n = srcattr.item(idx);
DOM_Node c = n.cloneNode(true);
dstattr.setNamedItem(c);
}
}
--
Miroslaw Dobrzanski-Neumann
MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne@mosaic-ag.com