IXMLDOMNode::get_lastChild
Previous | Next |
IXMLDOMNode::get_lastChild
The get_lastChild property retrieves the last child node.
Syntax
HRESULT get_lastChild( IXMLDOMNode** ppLastChild );
Parameters
ppLastChild
[out] Pointer to a pointer to an IXMLDOMNode 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.
Return Values
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Remarks
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 |
NODE_ATTRIBUTE NODE_DOCUMENT NODE_ELEMENT |
Retrieves a pointer to the last 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 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; } 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 |