Retrieving Playlist Entries
Previous | Next |
Retrieving Playlist Entries
The following code examples illustrate how to retrieve all of the elements in a playlist and the names and values of any attributes assigned to them.
Visual Basic .NET Example
Imports Microsoft.WindowsMediaServices.Interop Imports interop_msxml Private Sub RetrieveEntries() ' Declare variables. Dim Server As WMSServer Dim Playlist As IXMLDOMDocument Dim Node As IXMLDOMNode Dim NodeList As IXMLDOMNodeList Dim AttrNode As IXMLDOMNode Dim NodeAttributes As IXMLDOMNamedNodeMap Dim NodeName As String Dim NodeType As String Dim AttrName As String Dim AttrValue As String Dim I As Long Dim J As Long Try ' Create new server and playlist objects. Server = New WMSServer() Playlist = Server.CreatePlaylist ' Load an existing playlist from a file. Playlist.load("c:\wmpub\wmroot\playlist.wsx") ' Retrieve a list of all nodes in the playlist file. NodeList = Playlist.getElementsByTagName("*") ' Retrieve all elements and the attributes assigned to them. For I = 0 To NodeList.length - 1 ' Retrieve the next node in the playlist. Node = NodeList.item(I) ' Retrieve the name and type of the node. NodeName = Node.nodeName NodeType = Node.nodeType ' If the node is an element, retrieve the attributes. If NodeType = interop_msxml.DOMNodeType.NODE_ELEMENT Then NodeAttributes = Node.attributes ' Loop through all elements and retrieve the ' name and value of each. For J = 0 To NodeAttributes.length - 1 AttrNode = NodeAttributes.item(J) AttrName = AttrNode.nodeName AttrValue = AttrNode.nodeValue Next End If Next Catch Err As Exception ' TODO: Exception handler goes here. Finally ' TODO: Clean-up code goes here. End Try End Sub
C# Example
using Microsoft.WindowsMediaServices.Interop; using interop_msxml; // Declare variables. IXMLDOMDocument playlist; IXMLDOMNode attr_node, node; IXMLDOMNodeList node_list; IXMLDOMNamedNodeMap node_attributes; DOMNodeType node_type; string attr_name, attr_value, node_name; int i,j; try { // Create new server and playlist objects. WMSServer server = new WMSServerClass(); playlist = (IXMLDOMDocument)server.CreatePlaylist(); // Load an existing playlist from a file. playlist.load("c:\\wmpub\\wmroot\\playlist.wsx"); // Retrieve a list of all nodes in the playlist file. node_list = playlist.getElementsByTagName("*"); // Retrieve all elements and attributes. for (i=0; i<node_list.length; i++) { // Retrieve the next node in the playlist. node = node_list[i]; // Retrieve the name and type of the node. node_name = node.nodeName; node_type = node.nodeType; // If the node is an element, retrieve its attributes. if (node_type == DOMNodeType.NODE_ELEMENT) { node_attributes = node.attributes; // Retrieve the attributes for each element for (j=0; j < node_attributes.length; j++) { attr_node = node_attributes[j]; attr_name = attr_node.nodeName; attr_value = (string)attr_node.nodeValue; } } } } catch(Exception) { // TODO: Exception handler goes here. } finally { // TODO: Clean-up code goes here. }
C++ Example
// Include header files. #include <windows.h> #include <atlbase.h> // Includes CComBSTR and CComVariant. #include "wmsserver.h" // Declare variables and interfaces. IWMSServer *pServer; IXMLDOMDocument *pPlaylist; IXMLDOMNode *pAttrNode, *pNode; IXMLDOMNodeList *pNodeList; IXMLDOMNamedNodeMap *pNodeAttr; DOMNodeType *pNodeType; CComBSTR bstrAttrName, bstrAttrValue; CComBSTR bstrTemp, bstrName; CComVariant varValue; int i, j; long lLength; HRESULT hr; // Initialize the COM library and retrieve a pointer // to an IWMSServer interface. hr = CoInitialize(NULL); if (FAILED(hr))goto EXIT; hr = CoCreateInstance(CLSID_WMSServer, NULL, CLSCTX_ALL, IID_IWMSServer, (void **)&pServer); if (FAILED(hr))goto EXIT; // Create the playlist object. hr = pServer->CreatePlaylist(&pPlaylist); if (FAILED(hr))goto EXIT; // Retrieve the list of all nodes in the XML playlist file. bstrTemp = "*"; hr = pPlaylist->getElementsByTagName(bstrTemp, &pNodeList); if (FAILED(hr))goto EXIT; // Retrieve all elements and their attributes. hr = pNodeList->get_length(&lLength); if (FAILED(hr))goto EXIT; for (i=0; i < lLength; i++) { // Retrieve the next node in the playlist. hr = pNodeList->get_item((long)i, &pNode); if (FAILED(hr))goto EXIT; // Retrieve the name and type of the node. hr = pNode->get_nodeName(&bstrName); if (FAILED(hr))goto EXIT; hr = pNode->get_nodeType(pNodeType); if (FAILED(hr))goto EXIT; // If the node is an element, retrieve the attributes. if (*pNodeType == NODE_ELEMENT) { hr = pNode->get_attributes(&pNodeAttr); if (FAILED(hr))goto EXIT; // Loop through all elements and retrieve the // name and value of each. hr = pNodeAttr->get_length(&lLength); if (FAILED(hr))goto EXIT; for (j=0; j < lLength; j++) { hr = pNodeAttr->get_item((long)j, &pAttrNode); if (FAILED(hr))goto EXIT; hr = pAttrNode->get_nodeName(&bstrAttrName); if (FAILED(hr))goto EXIT; hr = pAttrNode->get_nodeValue(&varValue); if (FAILED(hr))goto EXIT; } } } EXIT: // TODO: Release temporary objects and uninitialize COM.
See Also (General)
See Also (Visual Basic .NET)
- IWMSServer Object (Visual Basic .NET)
- IXMLDOMDocument Object (Visual Basic .NET)
- IXMLDOMNamedNodeMap Object (Visual Basic .NET)
- IXMLDOMNode Object (Visual Basic .NET)
See Also (C#)
- IWMSServer Object (C#)
- IXMLDOMDocument Object (C#)
- IXMLDOMNamedNodeMap Object (C#)
- IXMLDOMNode Object (C#)
See Also (C++)
Previous | Next |