Collapse the table of content
Expand the table of content
Expand Minimize


The get_lastChild property retrieves the last child node.

HRESULT get_lastChild(
IXMLDOMNode** ppLastChild


[out] Pointer to a pointer to an IXMLDOMNodeIXMLDOMNode Interface representing the last child node. If there are no children, it returns NULL. This method calls AddRef internally. To avoid memory leaks, you must call Release when you are finished using the interface.

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

If there are no children, it returns NULL.

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

Node type

Value retrieved


Retrieves a pointer to the last child node. If there are no children, it returns NULL.


Returns NULL. This node type cannot have children.

The following example retrieves a pointer to an IXMLDOMNode interface, and then inserts an element before the last 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*          pXMLNewNode;

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)
    // Retrieve the root element.
    hr = pPlaylist->get_documentElement(&pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Retrieve a collection of child nodes and retrieve 
    // the last child node from that collection.
    hr = pXMLElement->get_childNodes(&pXMLNodeList);
    if (FAILED(hr)) goto EXIT;
    hr = pXMLNodeList->get_item(0, &pXMLNewNode);
    if (FAILED(hr)) goto EXIT;
    hr = pXMLElement->get_lastChild(&pXMLNewNode);
    if (FAILED(hr)) goto EXIT;

    // TODO: Release temporary COM objects and uninitialize COM.

Header: wmsserver.h.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003 family, Windows Server 2008 family.

© 2015 Microsoft