IXMLDOMElement Object (C#)

banner art

Previous Next

IXMLDOMElement Object (C#)

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

The IXMLDOMElement object supports the following properties and methods.

Property Description
attributes Contains the list of attributes for this node. Read-only.
childNodes Contains a node list containing 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.
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.
tagName Contains the element name (the name that appears within the tag). Read-only.

*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.
getAttribute Gets the value of the named attribute.
getAttributeNode Gets the named attribute node.
getElementsByTagName Returns a list of all descendant elements that match the supplied name.
hasChildNodes Returns a Boolean value indicating whether this node has children.
insertBefore Inserts a child node to the left of the specified node or at the end of the list.
removeAttribute Removes or replaces the named attribute.
removeAttributeNode Removes the specified attribute from this element.
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.
setAttribute Sets the value of the named attribute.
setAttributeNode Adds or changes the supplied attribute node on this element.
  • Note   For detailed information about using the C++ programming language to access the IXMLDOMElement object, see the IXMLDOMElement interface.

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 attributes of the element.

Example Code

The following example creates an IXMLDOMElement object and assigns it to the root element of an XML document.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMElement newRoot;

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

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

    // Create a new element named root.
    newRoot = Playlist.createElement("root");

    // Assign newRoot as the new document
    // element for the XML document.
    Playlist.documentElement = newRoot;
}
catch (Exception e) {
    // TODO: Handle exceptions.
}

See Also

Previous Next