IXMLDOMNamedNodeMap::setNamedItem
Previous | Next |
IXMLDOMNamedNodeMap::setNamedItem
The setNamedItem method adds the supplied node to the collection.
Syntax
HRESULT setNamedItem( IXMLDOMNode* pNewItem, IXMLDOMNode** ppNameItem );
Parameters
pNewItem
[in] Pointer to an IXMLDOMNode interface containing an attribute to be added to the collection.
ppNameItem
[out] Pointer to a pointer to an IXMLDOMNode interface containing the attribute added to the collection. 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
If an attribute already exists with the same name, the supplied attribute replaces the existing attribute. The attribute name can be retrieved by the IXMLDOMNode::get_nodeName method.
If the pNewItem node type is not NODE_ATTRIBUTE, setNamedItem returns an error. For example, it is not possible to modify entities or notations, which are read-only.
Example Code
The following example creates a new attribute and adds it to the element node using the setNamedItem method.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMNamedNodeMap* pXMLNamedNodeMap; IXMLDOMAttribute* pXMLAttribute; IXMLDOMNode* pXMLNode; 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; // Retrieve a pointer to an IXMLDOMNamedNodeMap interface. hr = pXMLElement->get_attributes(&pXMLNamedNodeMap); if (FAILED(hr)) goto EXIT; // Create a src attribute for the media element. bstrName = "src"; hr = pPlaylist->createAttribute(bstrName, &pXMLAttribute); if (FAILED(hr)) goto EXIT; // Set the value of the src attribute. varFile = "new_content.asf"; hr = pXMLAttribute->put_value(varFile); if (FAILED(hr)) goto EXIT; // Add the src attribute to the media element. hr = pXMLNamedNodeMap->setNamedItem(pXMLAttribute, &pXMLNode); 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
- IXMLDOMNamedNodeMap Interface
- IXMLDOMNamedNodeMap::getNamedItem
- IXMLDOMNode Interface
- XML DOM Methods (C++)
Previous | Next |