IXMLDOMDocument::createNode
Previous | Next |
IXMLDOMDocument::createNode
The createNode method creates a node using the supplied type, name, and namespace.
Syntax
HRESULT createNode( VARIANT varType, BSTR bstrName, BSTR bstrNamespaceURI, IXMLDOMNode** ppNode );
Parameters
varType
[in] VARIANT containing the value that uniquely identifies the node type. This can be specified using either the integer value or the string value.
bstrName
[in] BSTR containing the value for the new node's get_nodeName method. The relationship between the node name and node type is summarized in the table below.
bstrNamespaceURI
[in] BSTR defining the namespace Uniform Resource Identifier (URI). It does not matter what value is assigned to this BSTR because the Windows Media Services SDK implementation of the XML DOM does not fully support namespaces.
ppNode
[out] Pointer to a pointer to an IXMLDOMNode interface representing the newly created 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.
Remarks
The bstrName parameter depends on the value of the varType parameter as shown in the following table. For example, if the node type of the varType parameter is NODE_ELEMENT, the bstrName parameter will be the node name of the element node.
varType parameter | bstrName parameter |
NODE_COMMENT NODE_TEXT |
The retrieved value for the get_nodeName method for this node type is a constant value; the bstrName parameter is ignored. |
NODE_ELEMENT | The name of the XML element tag, with any namespace prefix included if present. |
NODE_PROCESSING_INSTRUCTION | The target (the first token following the <? characters). |
You cannot create a node of type NODE_ATTRIBUTE, NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, or NODE_NOTATION.
This method is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).
Example Code
The following example creates an element node called "media" and adds it to the attributes for the IXMLDOMDocument object.
#include "wmsserver.h" #include <atlbase.h> // Includes CComVariant and CComBSTR. // Declare variables. IWMSServer* pServer; IXMLDOMDocument* pPlaylist; IXMLDOMElement* pXMLElement; IXMLDOMNode* pXMLNewChild; IXMLDOMNode* pXMLOutNewChild; HRESULT hr; CComBSTR bstrName; CComBSTR bstrNamespaceURI; CComVariant varValue; CComVariant varNodeType; 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 an new node with the following parameters and // append it to the list of child nodes for the document. varNodeType = NODE_ELEMENT; bstrName = "media"; bstrNamespaceURI = ""; hr = pPlaylist->createNode(varNodeType, bstrName, bstrNamespaceURI, &pXMLNewChild); if (FAILED(hr)) goto EXIT; hr = pXMLElement->appendChild(pXMLNewChild, &pXMLOutNewChild); 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 |