IXMLDOMNamedNodeMap::get_item
Previous | Next |
IXMLDOMNamedNodeMap::get_item
The get_item method allows random access to individual nodes within the IXMLDOMNamedNodeMap collection.
Syntax
HRESULT get_item( long lIndex, IXMLDOMNode** ppListItem );
Parameters
lIndex
[in] long containing the index of the item within the collection. The first item is zero.
ppListItem
[out] Pointer to a pointer to an IXMLDOMNode interface. Returns NULL if the index is out of range. 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. If the index is out of range, it returns S_FALSE and ppListItem is set to NULL.
Example Code
The following example retrieves a pointer to an IXMLDOMNamedNodeMap interface with the document's get_attributes method. It then iterates through the collection.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMNamedNodeMap* pXMLNamedNodeMap; IXMLDOMNode* pXMLNode; HRESULT hr; VARIANT_BOOL bIsSuccessful; CComVariant varFile; long lCount; // 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. varFile = "c:\\wmpub\\wmroot\\simple.wsx"; hr = pPlaylist->load(varFile, &bIsSuccessful); if (FAILED(hr)) goto EXIT; if (bIsSuccessful) { // Retrieve a pointer to an IXMLDOMElement interface. hr = pPlaylist->get_documentElement(&pXMLElement); if (FAILED(hr)) goto EXIT; // Retrieve a pointer to an IXMLDOMNamedNodeMap interface. hr = pXMLElement->get_attributes(&pXMLNamedNodeMap); if (FAILED(hr)) goto EXIT; // Retrieve the number of nodes in the list. hr = pXMLNamedNodeMap->get_length(&lCount); if (FAILED(hr)) goto EXIT; // Retrieve each node in the list. for(long i = 0; i < lCount; i++)} { hr = pXMLNamedNodeMap->get_item(i, &pXMLNode); if (FAILED(hr)) goto EXIT; // Release temporary COM objects. pXMLNode->Release(); } } 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 |