IXMLDOMNode::get_firstChild

banner art

Previous Next

IXMLDOMNode::get_firstChild

The get_firstChild method retrieves the first child of the node.

Syntax

  HRESULT get_firstChild(
 IXMLDOMNode** ppFirstChild
);

Parameters

ppFirstChild

[out] Pointer to a pointer to an IXMLDOMNode interface representing the first child node. 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

The method retrieves the first child node. If there are no such children, it returns NULL.

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

Node type Value retrieved
NODE_ATTRIBUTE
NODE_DOCUMENT
NODE_ELEMENT
Retrieves the first child node. If there are no children, it returns NULL.
NODE_COMMENT
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
Returns NULL. This node type cannot have children.

Example Code

The following example retrieves the first child node of the top-level node.

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

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

HRESULT               hr;
CComVariant           varValue;
CComBSTR              bstrText;
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 IXMLDOMNode interface and
    // set pXMLNode to the first child node of the top-level node.
    hr = pXMLElement->get_firstChild(&pXMLNode);
    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