Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

importNode Method

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.

Note  In MSXML, "free-threaded" means ThreadingModel='Both', and cross-thread marshalling is supported.
[JScript]

Script Syntax

var clone = objXMLDOMDocument3.importNode(node, deep);
[Visual Basic]

Visual Basic Syntax

Set clone = objXMLDOMDocument3.importNode(node, deep);
[C/C++]

C/C++ Syntax Using Smart Pointers

IXMLDOMNodePtr clone = objXMLDOMDocument3->importNode(node, deep);

C/C++ Syntax

HRESULT IXMLDOMDocument3::importNode(
...[in] IXMLDOMNode* node,
   [in] VARIANT_BOOL deep,
...[out, retval] IXMLDOMNode** clone);

Parameters

node
An IXMLDOMNode object to be cloned.
deep
If true, any children of node will be cloned as well. If false, no children of node will be cloned.
clone
A clone of the node object, as specified above.

Return Values

S_OK
The node is cloned successfully.
E_FAIL
The node cannot be cloned properly and the resultant clone parameter is NULL.

Remarks

The importNode method does not allow for import of DOM nodes that are of one of the following enumerated node types: NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, and NODE_NOTATION.

In MSXML 5.0, deep must be VARIANT_TRUE, otherwise the method returns E_INVALIDARG.

Example

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.

Applies To

IXMLDOMDocument3

Versioning

MSXML 5.0 and later

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IXMLDOMNode | IXMLDOMNodeList | IXMLDOMParseError | IXMLDOMSchemaCollection/XMLSchemaCache