Share via


IXMLDOMElement.getElementsByTagName (C#)

banner art

Previous Next

IXMLDOMElement.getElementsByTagName (C#)

The getElelmentsByTagName method returns a list of all descendant elements that match the supplied name.

Syntax

  IXMLDOMNodeList = IXMLDOMElement
  .getElementsByTagName(
  string strtagName
);

Parameters

strtagName

[in] string specifying the name of the element to find. The string "*" matches all descendant elements of this element.

Return Values

Returns an IXMLDOMNodeList object containing all elements that match the supplied name.

Remarks

Elements appear in the order encountered in a preorder traversal of this element's tree.

The IXMLDOMNodeList object is returned even if there are no matches. In this case, the length of the list will be set to zero.

The IXMLDOMNodeList object is live and immediately reflects changes to the nodes that appear in the list.

Example Code

The following example creates an IXMLDOMNodeList object by using the IXMLDOMElement.getElementsByTagName method, and then displays all of the elements with the desired tag name.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

// Declare variables.
WMSServer Server;
IXMLDOMDocument Playlist;
IXMLDOMElement Elem;
IXMLDOMNodeList nodelistMedia;

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");

    // Get all the elements that match the query.
    Elem = Playlist.documentElement;
    nodelistMedia = Elem.getElementsByTagName("media");

    // Iterate through the node list and display the node value
    // of every attribute for every node in the list.
    for(int i = 0; i < nodelistMedia.length; i++)
    {
            MessageBox.Show(nodelistMedia[i].attributes[0].nodeValue.ToString());
    }
}
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