IXMLDOMNode::put_nodeValue
Previous | Next |
IXMLDOMNode::put_nodeValue
The put_nodeValue method specifies the text associated with the node.
Syntax
HRESULT put_nodeValue( VARIANT varValue );
Parameters
varValue
[in] VARIANT containing the node value; depends on the get_nodeType method.
Return Values
If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.
Remarks
Specifying the value of the VARIANT depends on the type of node on which the nodeValue property is called, as shown in the following table. For example, if the node type is NODE_ATTRIBUTE, a BSTR representing the value for that attribute node is set.
Node type | Value set |
NODE_ATTRIBUTE | Setting this value deletes all children of the node and replaces them with a single text node containing the value written. |
NODE_COMMENT | Contains the content of the comment, exclusive of the comment's start and end sequence. |
NODE_ELEMENT NODE_DOCUMENT |
Returns NULL. Attempting to set the value of nodes of these types generates an error. |
NODE_PROCESSING_INSTRUCTION | Contains the processing instruction, excluding the target. (The target appears in the nodeName method.) |
NODE_TEXT | Contains a string representing the text stored in the text node. |
Example Code
The following example retrieves a pointer to an IXMLDOMNode interface and tests whether it is a processing instruction node. If it is, it is assigned a node value.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMNodeList* pXMLNodeList; IXMLDOMNode* pXMLNode; HRESULT hr; CComVariant varValue; CComVariant varNodeValue; CComBSTR bstrType; 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 IXMLNodeList interface. hr = pPlaylist->get_childNodes(&pXMLNodeList); if (FAILED(hr)) goto EXIT; // Get the first node in the node list and // retrieve the node type. hr = pXMLNodeList->get_item(0, &pXMLNode); if (FAILED(hr)) goto EXIT; hr = pXMLNode->get_nodeTypeString(&bstrType); if (FAILED(hr)) goto EXIT; // If the node type is PROCESSING_INSTRUCTION, // then assign the node value of "wsx" to it. if (bstrType == "processinginstruction") { varNodeValue = "wsx"; hr = pXMLNode->put_nodeValue(varNodeValue); 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 |