IXMLDOMAttribute Object (C#)

banner art

Previous Next

IXMLDOMAttribute Object (C#)

The IXMLDOMAttribute object represents an attribute of the IXMLDOMElement object. For more information, see the Microsoft XML SDK 3.0 documentation available at the Microsoft Web site.

The IXMLDOMAttribute object supports the following properties and methods for describing an IXMLDOMElement object.

Property Description
attributes Contains the list of attributes for this node. Read-only.
childNodes Contains a list of the children (for nodes that can have children). Read-only.
firstChild Contains the first child of this node. Read-only.
lastChild Contains the last child of this node. Read-only.
name Contains the attribute name. Read-only.
nextSibling Contains the next sibling of this node in the parent's child list. Read-only.
nodeName Contains the qualified name of the element, attribute, or entity reference, or a fixed string for other node types. Read-only.
nodeType Specifies the XML DOM node type, which determines valid values and whether the node can have child nodes. Read-only.
nodeTypeString* Contains the node type in string form. Read-only.
nodeValue Contains the text associated with the node. Read/write.
ownerDocument Returns the root of the document that contains this node. Read-only.
parentNode Contains the parent node (for nodes that can have parents). Read-only.
previousSibling Contains the left sibling of this node. Read-only.
value Contains the attribute value. Read/write.

*Denotes an extension to the W3C DOM.

Method Description
appendChild Appends the supplied new child as the last child of this node.
cloneNode Creates a new node that is an exact clone of this node.
hasChildNodes Returns a Boolean value of true if this node has children.
insertBefore Inserts a child node to the left of the specified node or at the end of the list.
removeChild Removes the specified child node from the list of children and returns it.
replaceChild Returns the specified old child node and replaces it with the supplied new child node.
  • Note   For detailed information about using the C++ programming language to access the IXMLDOMAttribute object, see the IXMLDOMAttribute interface.

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.

IXMLDOMAttribute objects inherit from the IXMLDOMNode object, but 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. Thus, the object's parentNode, previousSibling, and nextSibling properties have the value NULL.

Example Code

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

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMElement Root;
IXMLDOMAttribute objDOMatt;


try {
    // Create a new WMSServer object.
    Server = new WMSServer();

    // Create a new playlist object.
    Playlist = Server.CreatePlaylist();

    // Load a sample playlist file.
    Playlist.load("file://c:\\wmpub\\wmroot\\simple.wsx");

    // Retrieve the root element.
    Root = Playlist.documentElement;

    // Create an IXMLDOMAttribute object and display the
    // attribute value of the first item in the first child node.
    objDOMatt = (IXMLDOMAttribute)Root.firstChild.attributes[0];
    MessageBox.Show(objDOMatt.value.ToString());
}
catch (Exception e) {
    // TODO: Handle exceptions.
}

See Also

Previous Next