Share via


IXMLDOMNode::get_ownerDocument

banner art

Previous Next

IXMLDOMNode::get_ownerDocument

The get_ownerDocument method retrieves the root of the document that contains the node.

Syntax

  HRESULT get_ownerDocument(
 IXMLDOMDocument** ppDOMDocument
);

Parameters

ppDOMDocument

[out] Pointer to a pointer to an IXMLDOMDocument interface representing the address of the parent document object that represents the root of the document. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

Return Values

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

Remarks

This method retrieves the parent document that represents the root of the document to which this node belongs.

Example Code

The following example uses the get_ownerDocument method to return the parent IXMLDOMDocument object, and then retrieves that object's root element tag name.

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

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMDocument*      pXMLOwnerDoc;
IXMLDOMElement*       pXMLElement;
IXMLDOMNodeList*      pXMLNodeList;
IXMLDOMNode*          pXMLNode;

HRESULT               hr;
CComVariant           varValue;
CComBSTR              bstrName;
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)
{
    // 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, &pXMLNode);
    if (FAILED(hr)) goto EXIT;
    
    // Retrieve a pointer to the owner document 
    // and retrieve a pointer to the root element.
    hr = pXMLNode->get_ownerDocument(&pXMLOwnerDoc);
    if (FAILED(hr)) goto EXIT;
    hr = pXMLOwnerDoc->get_documentElement(&pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Display the tag name for the root element of
    // the owner document.
    hr = pXMLElement->get_tagName(&bstrName);
    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