IXMLDOMElement Interface

The IXMLDOMElement interface represents the element object. For more information, see the Microsoft XML SDK 3.0 documentation available at the Microsoft Web site.

In addition to the methods inherited from the IXMLDOMNodeIXMLDOMNode Interface, the IXMLDOMElement interface exposes the following methods.

Method

Description

get_tagName

Retrieves the element name(that appears within the tag).

getAttribute

Retrieves the value of the named attribute.

getAttributeNode

Retrieves the named attribute node.

getElementsByTagName

Retrieves a list of all descendant elements that match the supplied name.

removeAttribute

Removes or replaces the named attribute.

removeAttributeNode

Removes the specified attribute from this element.

setAttribute

Specifies the value of the named attribute.

setAttributeNode

Adds or changes the supplied attribute node on this element.

Remarks

Element nodes are among the most common objects in the XML document tree. Element nodes can have attributes associated with them. By definition, attributes are not defined as child nodes of the element and are not considered to be part of the document tree. Accordingly, the IXMLDOMElement object provides methods to make it easier to manage attributes, including methods to associate an attribute with an element, and to retrieve an attribute object and the attribute value by name.

To retrieve the set of all attributes associated with the element, you can also call the getAttribute method, which returns an IXMLDOMNamedNodeMap collection object that contains all the element's attributes.

Example

The following example retrieves a pointer to an IXMLDOMElement interface and assigns it as the new document element of an XML document.

#include “wmsserver.h”
#include <atlbase.h> // Includes CComVariant and CComBSTR.

// Declare variables.
IWMSServer*           pServer;
IXMLDOMDocument*      pPlaylist;
IXMLDOMElement*       pXMLElement;

HRESULT               hr;
CComVariant           varFile;
VARIANT_BOOL          bIsSuccessful;
CComBSTR              bstrName;

// 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.
varFile = "c:\\wmpub\\wmroot\\simple.wsx";
hr = pPlaylist->load(varFile, &bIsSuccessful);
if (FAILED(hr)) goto EXIT;

if (bIsSuccessful)
{
    // Create a new element named "root."
    bstrName = "root";
    hr = pPlaylist->createElement(bstrName, &pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Assign pXMLElement as the new document element
    // for the XML document.
    hr = pPlaylist->putref_documentElement(pXMLElement);
    if (FAILED(hr)) goto EXIT;
}

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

See Also

Reference

IXMLDOMNamedNodeMap Interface

IXMLDOMNode Interface