IXMLDOMNode::get_parentNode

The get_parentNode method retrieves the parent node of the IXMLDOMNode object.

HRESULT get_parentNode(
IXMLDOMNode** ppParent
);

Arguments

ppParent

[out] Pointer to a pointer to an IXMLDOMNodeIXMLDOMNode Interface that represents the parent of the given node instance. 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

All nodes except document and attribute nodes can have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, the parent is NULL.

The value of the IXMLDOMNode interface retrieved depends on the type of node on which the get_parentNode method is called, as shown in the following table. For example, if the node type is NODE_ELEMENT, the parent node for that element node is retrieved.

Node type

Value retrieved

NODE_ATTRIBUTE NODE_DOCUMENT

Returns NULL; these nodes do not have parents.

NODE_COMMENT

Retrieves the element, entity reference, document type, or document containing the comment.

NODE_ELEMENT

Retrieves the parent node of the element. If the element is the root node in the tree, the parent is the document node. If the node is the document node, parentNode is NULL.

NODE_PROCESSING_INSTRUCTION

Retrieves the document or element, containing the processing instruction.

NODE_TEXT

Retrieves the parent element or attribute.

Example

The following example retrieves a pointer to an IXMLDOMNode interface from another node object's parent.

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

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMElement*       pXMLElement;
IXMLDOMNodeList*      pXMLNodeList;
IXMLDOMNode*          pXMLCurrNode;
IXMLDOMNode*          pXMLParentNode;

HRESULT               hr;
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)
{
    // 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 and 
    // use it to access the parent node.
    hr = pXMLNodeList->get_item(0, &pXMLCurrNode);
    if (FAILED(hr)) goto EXIT;
    hr = pXMLCurrNode->get_parentNode(&pXMLParentNode);
    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

Reference

IXMLDOMNode Interface

Concepts

XML DOM Methods (C++)