IXMLDOMElement::setAttribute
Previous | Next |
IXMLDOMElement::setAttribute
The setAttribute method specifies the value of the named attribute.
Syntax
HRESULT setAttribute( BSTR bstrName, VARIANT varValue );
Parameters
bstrName
[in] BSTR containing the name of the attribute. If an attribute with that name already exists, its value is changed. If an attribute with that name does not exist, it is created.
varValue
[in] VARIANT containing the value for the named attribute.
Return Values
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Remarks
If an attribute with the supplied name already exists, this method changes that attribute's value to the value supplied in the varValue parameter. The supplied bstrName parameter is not parsed, so any markup, such as syntax meant to be recognized as an entity reference, is treated as literal text and must be appropriately escaped by the implementation when it is written out.
Example Code
The following example sets the name and value of a new attribute for the specified element node.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; HRESULT hr; CComBSTR bstrName; CComVariant varFile; // 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; 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 |