Share via


IXMLDOMElement::getAttribute

banner art

Previous Next

IXMLDOMElement::getAttribute

The getAttribute method retrieves the value of the attribute.

Syntax

  HRESULT getAttribute(
 BSTR bstrName,
 VARIANT* varValue
);

Parameters

bstrName

[in] BSTR containing the name of the attribute to return.

varValue

[out] Pointer to a VARIANT that contains the attribute value. The empty string is returned if the named attribute does not have a specified or default value.

Return Values

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

Remarks

You can also retrieve attributes by using the getNamedItem method of the IXMLDOMNamedNodeMap interface.

Example Code

The following example retrieves the value of an IXMLDOMAttribute object named "src" using the getAttribute method.

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

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

HRESULT             hr;
CComBSTR            bstrName;
CComVariant         varFile;
CComVariant         varAttValue;

// 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);

// Create a media element.
bstrName = "media";
hr = pPlaylist->createElement(bstrName, &pXMLElement);
if (FAILED(hr)) goto EXIT;

// Set the src attribute for the media element.
bstrName = "src";
varFile = "welcome1.asf";
hr = pXMLElement->setAttribute(bstrName, varFile);
if (FAILED(hr)) goto EXIT;

// Retrieve the value for the attribute named "src".
bstrName = "src";
hr = pXMLElement->getAttribute(bstrName, &varAttValue);
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