IXMLDOMDocument::createAttribute
Previous | Next |
IXMLDOMDocument::createAttribute
The createAttribute method creates a new attribute with the specified name.
Syntax
HRESULT createAttribute( BSTR bstrName, IXMLDOMAttribute** ppAttribute );
Parameters
bstrName
[in] BSTR specifying the name of the new attribute object. This name is subsequently available as the new node's get_nodeName method.
ppAttribute
[out] Pointer to a pointer to an IXMLDOMAttribute interface. 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
No data value is set for the attribute during the create operation. You can set the value by calling the setAttribute method of the element object.
The get_parentNode method always returns NULL.
The get_nodeType method has the value NODE_ATTRIBUTE.
Example Code
The following example creates a new attribute called ID and adds it to the attributes of the IXMLDOMDocument object.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMAttribute* pXMLAttribute; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMNamedNodeMap* pXMLNamedNodeMap; IXMLDOMNode* pXMLNewNode; HRESULT hr; CComBSTR bstrName; CComBSTR bstrValue; CComVariant varValue; VARIANT_BOOL bIsSuccessful; // 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; // Create a new attribute for the root element. bstrName = "ID"; hr = pPlaylist->createAttribute(bstrName, &pXMLAttribute); if (FAILED(hr)) goto EXIT; // Add the new attribute to the collection of nodes. hr = pXMLElement->get_attributes(&pXMLNamedNodeMap); if (FAILED(hr)) goto EXIT; hr = pXMLNamedNodeMap->setNamedItem(pXMLAttribute, &pXMLNewNode); if (FAILED(hr)) goto EXIT; // Display the attribute name. hr = pXMLNewNode->get_nodeName(&bstrValue); 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 |