IXMLDOMElement.setAttribute (C#)

banner art

Previous Next

IXMLDOMElement.setAttribute (C#)

The setAttribute method sets the value of the named attribute.

Syntax

  IXMLDOMElement
  .setAttribute(
  string strName,
 object varValue 
);

Parameters

strName

[in] string specifying the name of the attribute. If the attribute with that name already exists, its value is changed. If the attribute with that name does not exist, it is created.

varValue

[in] object that supplies the value for the named attribute.

Remarks

If an attribute with the supplied name already exists, this method changes that attribute's value to the value supplied in the varValue parameter. The supplied strName parameter is not parsed, so any markup, such as syntax meant to be recognized as an entity reference, is treated as literal text and must be appropriately escaped by the implementation when it is written out.

Example Code

The following example sets the name and value of a new attribute for the specified element node.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMNodeList ElemList;
IXMLDOMElement Elem;
IXMLDOMNode Node;

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

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

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

    // Retrieve a list of nodes that matches the query.
    ElemList = Playlist.getElementsByTagName("media");

    // Retrieve the first node in the list.
    Node = ElemList[0];

    // Box the first node into an IXMLDOMElement object.
    Elem = (IXMLDOMElement)Node;

    // Set the value for the attribute named "src".
    Elem.setAttribute("src", "new_content.asf");
}
catch (Exception e) {
    // TODO: Handle exceptions.
}

Requirements

Reference: Add references to Microsoft.WindowsMediaServices and interop_msxml.

Namespace: Microsoft.WindowsMediaServices.Interop, interop_msxml.

Assembly: Microsoft.WindowsMediaServices.dll, interop_msxml.dll.

Library: WMSServerTypeLib.dll, msxml.dll.

Platform: Windows Server 2003 family, Windows Server 2008 family.

See Also

Previous Next