IXMLDOMNode::cloneNode
The cloneNode method creates a new node that is an exact clone of this node.
HRESULT cloneNode(
VARIANT_BOOL bDeep,
IXMLDOMNode** ppCloneRoot
);
Arguments
bDeep |
[in] VARIANT_BOOL that indicates whether to recursively clone all nodes that are descendants of this node. If true, create a clone of the complete tree below this node. If false, clone this node and its attributes only. |
ppCloneRoot |
[out] Pointer to a pointer to an IXMLDOMNode interface representing a newly created clone node. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface. |
Return Value
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Remarks
The cloned node has the same values as this node for the following methods: get_nodeName, get_nodeValue, get_nodeType, get_parentNode, get_ownerDocument, and, if it is an element, the get_attributes method. The value of the clone's get_childNodes method depends on the setting of the flag parameter.
Example
The following example clones a node, and then appends the clone as a child of the top-level node.
#include “wmsserver.h”
#include <atlbase.h> // Includes CComVariant and CComBSTR.
// Declare variables.
IWMSServer* pServer;
IXMLDOMDocument* pPlaylist;
IXMLDOMElement* pXMLElement;
IXMLDOMNodeList* pXMLNodeList;
IXMLDOMNode* pXMLCurrNode;
IXMLDOMNode* pXMLNewNode;
IXMLDOMNode* pXMLOutNewNode;
HRESULT hr;
CComVariant varValue;
VARIANT_BOOL bIsSuccessful;
VARIANT_BOOL bdeep;
// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer, NULL, CLSCTX_ALL,
IID_IWMSServer, (void**)&pServer);
if (FAILED(hr)) goto EXIT;
// Create the playlist object.
hr = pServer->CreatePlaylist(&pPlaylist);
// Load a sample playlist file.
varValue = "c:\\wmpub\\wmroot\\simple.wsx";
hr = pPlaylist->load(varValue, &bIsSuccessful);
if (FAILED(hr)) goto EXIT;
if (bIsSuccessful)
{
// Retrieve a pointer to the IXMLDOMElement interface.
hr = pPlaylist->get_documentElement(&pXMLElement);
if (FAILED(hr)) goto EXIT;
// Retrieve a pointer to the IXMLNodeList interface.
hr = pXMLElement->get_childNodes(&pXMLNodeList);
if (FAILED(hr)) goto EXIT;
// Get the first node in the node list.
hr = pXMLNodeList->get_item(0, &pXMLCurrNode);
if (FAILED(hr)) goto EXIT;
// Clone current node and append it to the root element.
bdeep = true;
hr = pXMLCurrNode->cloneNode(bdeep, &pXMLNewNode);
if (FAILED(hr)) goto EXIT;
hr = pXMLElement->appendChild(pXMLNewNode, &pXMLOutNewNode);
if (FAILED(hr)) goto EXIT;
}
EXIT:
// TODO: Release temporary COM objects and uninitialize COM.
Requirements
Header: wmsserver.h.
Library: WMSServerTypeLib.dll.
Platform: Windows Server 2003 family, Windows Server 2008 family.