IXMLDOMElement::setAttributeNode
Previous | Next |
IXMLDOMElement::setAttributeNode
The setAttributeNode method specifies or updates the supplied attribute node on this element.
Syntax
HRESULT setAttributeNode( IXMLDOMAttribute* pDOMAttribute, IXMLDOMAttribute** ppAttributeNode );
Parameters
pDOMAttribute
[in] Pointer to an IXMLDOMAttribute interface containing the attribute node that is to be associated with this element.
ppAttributeNode
[out] Pointer to a pointer to an IXMLDOMAttribute interface. This parameter is NULL unless the new attribute replaces an existing attribute with the same name, in which case this method retrieves the previous, replaced attribute node. 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.
Example Code
The following example creates an attribute node and adds it to the specified element node.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMAttribute* pXMLAttribute; IXMLDOMAttribute* pXMLAttributeOld; 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; // Create a src attribute. bstrName = "src"; hr = pPlaylist->createAttribute(bstrName, &pXMLAttribute); if (FAILED(hr)) goto EXIT; // Set the value for the src attribute. varFile = "welcome1.asf"; hr = pXMLAttribute->put_value(varFile); if (FAILED(hr)) goto EXIT; // Add the new attribute to the media element. hr = pXMLElement->setAttributeNode(pXMLAttribute, &pXMLAttributeOld); 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
- IXMLDOMAttribute Interface
- IXMLDOMElement Interface
- IXMLDOMElement::getAttributeNode
- XML DOM Methods (C++)
Previous | Next |