Share via


IXMLDOMDocument.getElementsByTagName (C#)

banner art

Previous Next

IXMLDOMDocument.getElementsByTagName (C#)

The getElementsByTagName method returns a collection of elements that have the specified name.

Syntax

  IXMLDOMNodeList = IXMLDOMDocument
  .getElementsByTagName(
  string strtagName
);

Parameters

strtagName

[in] string specifying the element name to find. The string "*" returns all elements in the document.

Return Values

Returns a collection of elements that match the specified name.

Remarks

The elements in the collection are returned in the order in which they would be encountered in a preorder traversal of the document tree. In a preorder traversal, the parent root node is visited first and each child node from left to right is then traversed.

The returned 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 IXMLDOMDocument.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;
IXMLDOMNodeList NodeList;

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 match the query.
    NodeList = Playlist.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 < NodeList.length; i++)
    {
            MessageBox.Show(NodeList[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