[This sample code uses features that were implemented only in MSXML 6.0.]
This method can be used to clone a node from a DOM object. In addition to supporting all the functionality offered by the cloneNode method, it enables cloning a node from DOM objects of different threading models. The clones created this way can be passed between such DOM objects. For example, a node from a free-threaded DOM object can be passed into an apartment-threaded DOM object. The resultant node object can then be added into the document using the appendChild method.
In MSXML, "free-threaded" means ThreadingModel='Both', and cross-thread marshalling is supported.
IXMLDOMNodePtr clone = objXMLDOMDocument6->importNode(node, deep); HRESULT IXMLDOMDocument3::importNode( ...[in] IXMLDOMNode* node, [in] VARIANT_BOOL deep, ...[out, retval] IXMLDOMNode** clone);
This example demonstrates how to use importNode to clone a node from a free-threaded DOM document and append the clone to a regular apartment-threaded DOM object. As a comparison, it also shows that a DOM object can clone a node from itself with importNode, just as it would with cloneNode.
We've provided source files for the sample in three languages: JScript, Visual Basic, and C++. The output is the same in each language.