Partager via


IXMLDOMAttribute Interface

The IXMLDOMAttribute interface represents an attribute of the element object that is generated by the IXMLDOMElementIXMLDOMElement Interface. 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 IXMLDOMAttribute interface exposes the following methods.

Method

Description

get_name

Retrieves the attribute name.

get_value

Retrieves the attribute value.

put_value

Specifies the attribute value.

Remarks

In XML, the value of an attribute is represented by the child nodes of the attribute node because the value can contain entity references. Thus attributes that contain entity references will have a child list containing both text nodes and entity reference nodes. In addition, because the attribute type might be unknown, there are no tokenized attribute values.

Although the IXMLDOMAttribute interface inherits from the IXMLDOMNode interface, the objects generated by the IXMLDOMAttribute interface are not actually child nodes of the element and are not considered part of the document tree. Attributes are considered to be members of their associated elements, rather than independent and separate child nodes. Thus, the object's parentNode, previousSibling, and nextSibling methods have the value NULL.

Example

The following example creates an IXMLDOMAttribute interface from the first attribute of the root element and retrieves the object's attribute value.

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

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

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

if (bIsSuccessful)
{
    // Retrieve a pointer to an IXMLElement interface.
    hr = pPlaylist->get_documentElement(&pXMLElement);
    if (FAILED(hr)) goto EXIT;

    // Set an attribute associated with the element with
    // the values listed below.
    bstrName = "document";
    varValue = "version 1.0";
    hr = pXMLElement->setAttribute(bstrName, varValue);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the attribute node with the node name "document."
    hr = pXMLElement->getAttributeNode(bstrName, &pXMLAttribute);
    if (FAILED(hr)) goto EXIT;

    // Retrieve the value associated with that attribute.
    hr = pXMLAttribute->get_value(&varAttValue);
    if (FAILED(hr)) goto EXIT;
}

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

See Also

Reference

IXMLDOMElement Interface

IXMLDOMNode Interface