IXMLDOMNode::get_attributes
Previous | Next |
IXMLDOMNode::get_attributes
The get_attributes method retrieves the list of attributes for this node.
Syntax
HRESULT get_attributes( IXMLDOMNamedNodeMap** ppAttributeMap );
Parameters
ppAttributeMap
[out] Pointer to a pointer to an IXMLDOMNamedNodeMap interface that is retrieved for nodes that can return attributes. Returns NULL for all other node types. 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
For the valid node types, a pointer to an IXMLDOMNamedNodeMap interface is always retrieved; when there are no attributes on the element, the list length is set to zero.
The value of the IXMLDOMNamedNodeMap interface retrieved depends on the type of node on which the get_attributes method is called, as shown in the following table. For example, if the node type is NODE_ELEMENT, a list of attribute nodes for that element node is retrieved.
Node type | Value retrieved |
NODE_ATTRIBUTE NODE_COMMENT NODE_DOCUMENT NODE_TEXT |
Always returns NULL. |
NODE_ELEMENT | Retrieves a pointer to an IXMLDOMNamedNodeMap interface that contains a list of nodes corresponding to the attributes of the element. |
NODE_PROCESSING_INSTRUCTION | Returns NULL for all processing instructions except the XML declaration; for example,
<?xml version="1.0" encoding="windows-1252" standalone="yes" ?>. For the XML declaration, the version, encoding, and stand-alone specifications can be accessed as attributes from the corresponding node. |
Example Code
The following example retrieves a pointer to an IXMLDOMNamedNodeMap interface from a document's get_attributes method, and then displays the number of nodes in the object.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMNamedNodeMap* pXMLNamedNodeMap; HRESULT hr; CComVariant varValue; VARIANT_BOOL bIsSuccessful; 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. 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 IXMLDOMNamedNodeMap interface. hr = pXMLElement->get_attributes(&pXMLNamedNodeMap); if (FAILED(hr)) goto EXIT; // Retrieve the total count of attributes. hr = pXMLNamedNodeMap->get_length(&lCount); 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 |