IXMLDOMDocument::putref_documentElement

banner art

Previous Next

IXMLDOMDocument::putref_documentElement

The putref_documentElement method specifies the root element of the document.

Syntax

  HRESULT putref_documentElement(
 IXMLDOMElement* pDOMElement
);

Parameters

pDOMElement

[in] Pointer to an IXMLDOMElement interface that represents the root of the XML document tree. Returns NULL if no root exists.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Remarks

When calling the putref_documentElement method, the specified element node is inserted into the child list of the document after any document type node.

To precisely place the node within the children of the document, call the IXMLDOMNode::insertBefore method.

The get_parentNode method is reset to the document node as a result of this operation.

Example Code

The following example retrieves a pointer to an IXMLDOMElement interface and assigns it to be the root element of the document by using the putref_documentElement method. It then traverses the document tree.

#include "wmsserver.h"
#include <atlbase.h> // Includes CComVariant and CComBSTR.

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMElement*       pXMLElement;

HRESULT               hr;
CComBSTR              bstrName;
CComVariant           varValue;
VARIANT_BOOL          bIsSuccessful;

// 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)
{
    // Create a media element.
    bstrName = "media";
    hr = pPlaylist->createElement(bstrName, &pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Assign new media element as the root element 
    // in the XML document.
    hr = pPlaylist->putref_documentElement(pXMLElement);
    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.

See Also

Previous Next