IXMLDOMNamedNodeMap.setNamedItem (C#)

banner art

Previous Next

IXMLDOMNamedNodeMap.setNamedItem (C#)

The setNamedItem method adds the supplied node to the collection.

Syntax

  IXMLDOMNode = IXMLDOMNamedNodeMap
  .setNamedItem(
  IXMLDOMNode newItem
);

Parameters

newItem

[in] IXMLDOMNode object containing the attribute to be added to the collection.

Return Values

Returns the attribute added to the collection.

Remarks

If an attribute already exists with the same name, the supplied attribute replaces the existing attribute. The attribute name appears in the IXMLDOMNode.nodeName property.

If the newItem node type is not NODE_ATTRIBUTE, setNamedItem returns an error. For example, it is not possible to modify entities or notations because they are read-only.

Example Code

The following example creates a new attribute and adds it to the element node using the setNamedItem method.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMElement Elem;
IXMLDOMNodeList ChildList;
IXMLDOMNamedNodeMap XMLNamedNodeMap;
IXMLDOMAttribute NodeMedia;

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 pointer to the root element.
    Elem = Playlist.documentElement;

    // Retrieve a list of the child nodes.
    ChildList = Elem.childNodes;

    // Retrieve the list of attributes for the first
    // node in the child node list.
    XMLNamedNodeMap = ChildList[0].attributes;

    // Create a new attribute.
    NodeMedia = Playlist.createAttribute("src");

    // Set the value of the new attribute.
    NodeMedia.value = "new_content.asf";

    // Add the src attribute to the media element.
    XMLNamedNodeMap.setNamedItem(NodeMedia);
}
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