Share via


IXMLDOMDocument.documentElement (C#)

banner art

Previous Next

IXMLDOMDocument.documentElement (C#)

The documentElement property contains the root element of the document.

Syntax

  IXMLDOMElement = IXMLDOMDocument
  .documentElement;
IXMLDOMDocument.documentElement = IXMLDOMElement;

Remarks

The property is read/write. It returns the IXMLDOMElement object that represents the root of the XML document tree. It returns NULL if no root exists.

When setting the documentElement property, the specified element node is inserted into the child list of the document after any document type node. To precisely place the node within the children of the document, call the IXMLDOMNode.insertBefore method.

The parentNode property is reset to the document node as a result of this operation.

Example Code

The following example creates an IXMLDOMElement object and sets it to the root element of the document by using the documentElement property. It then traverses the document tree.

using Microsoft.WindowsMediaServices.Interop;
using interop_msxml;

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

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

    // Display the node value from every attribute in the child nodes.
    for(int i = 0; i < Root.childNodes.length; i++)
    {
           MessageBox.Show(Root.childNodes[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