grass valley developers

Home > APIs > AppServer API > Examples > Asset Management > Get Information from a Clip's XML Representation

Get Information from a Clip's XML Representation

You can get any information about a clip by creating an editor object for the clip and then asking the editor for the clip's XML representation. Once you have the XML, you can use an XPath query to select the node or nodes that you are interested in.

The example below shows, in this case, how to get the media segment's filename for track one's audio file. See the sample clip XML file below for reference.

The full sample script can be downloaded from the example scripts page or from here: GetInfoFromClip.cs

// define the clip that we're going to inspect.
string clipname = "V:/default/Clip";
string fullclipname = "edl/cmf//local/" + clipname;

// get an editor for clip
IMediaMgr mediaMgr = iappServer.CreateMediaMgr(appName);
ITrackEditor trackEditor = (ITrackEditor) mediaMgr.CreateEditor(fullclipname);

// get the clip's XML representation
string xml;
trackEditor.GetXml("", out xml);			

// get the clip's XML representation
string xml;
trackEditor.GetXml("", out xml);			


// NOTE: a sample XML file is listed below for reference.


// load the xml string into a native XmlDocument
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

// setup a namespace manager to parse the xml doc
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
namespaceManager.AddNamespace("ns", "PdrDB__1.0");


// get media segment nodes - notice this is filtering for track = "1", filetype = "FileTypeAudio". 
// check the XML above to determine what you want to filter on...
XmlNodeList mediaSegmentList = xmlDoc.SelectNodes(("//ns:XML/ns:Data/ns:Movie/ns:Track[@TrackNumber='1']/ns:Segment/ns:MediaSegment[@FileType='FileTypeAudio']"), namespaceManager);

// this is a good sanity check to see the number of nodes returned
// Console.WriteLine("count = " + mediaSegmentList.Count);

foreach (XmlNode mediaSegment in mediaSegmentList)
{
	// the clip's media segment filename
	string fileName = mediaSegment.Attributes.GetNamedItem("FileName").Value;
	Console.WriteLine(fileName);

	// how to get an integer attribute value
	// int sampleRate = Int32.Parse(mediaSegment.Attributes.GetNamedItem("SampleRate").Value); // sample rate like 4800
	// Console.WriteLine("sample rate = " + sampleRate);
}

// be sure to cleanup or you will leak these objects!
trackEditor.Detach();
trackEditor.Dispose();
mediaMgr.Dispose();
Sample Clip XML for reference: