In the previous article about Youtube API Search in ASP.Net C# we learnt the use of XmlDataSource control to read the Youtube API Search RSS feed response. In this tutorial we have used the dynamic XmlDataSource Control class object to read the RSS feed of Search results from Youtube API. In C# code you can create an object of XmlDataSource control by using System.Xml namespace. It allows you to access the XmlDataSource control properties such as DataFile and XPath programmatically to parse the RSS formatted Response of Youtube Search API. While reading the XML format as RSS response you need to parse and access the Xml nodes having namespace prefixes such as openSearch and media e.g.: openSearhc:totalResults, media:category etc. To read these xml nodes with namespace prefix XmlNamespaceManager class object is used. XmlNamespaceManager class provides the AddNamespace method to include the namespace name and its XML schema definition URL that allows reading the XML nodes having prefixes. In the following example code you will learn how to pass the user input keyword to the Youtube API search method and retrieve the relevant results.
// XmlDataSource Control Dynamic Object
XmlDataSource xmlSource = new XmlDataSource();
// XmlNamespaceManager initialized by passing the Xml Document NameTable
xmlN.AddNamespace("media", "http://search.yahoo.com/mrss/");
// XmlNodeList generated by passing XPath expression and XmlNamespaceManager Object
Repeater1.DataSource = xmlNodes;
Repeater1.DataBind();
Output:
You can download the above free ASP.Net Youtube API Search script below:
youtube-keyword-search.zip (2.09 kb)
Be the first to rate this post
Tags: asp.net 2.0, rss, c#, xml, youtube api, asp.net repeater control, asp.net xmldatasource control, youtube api search, asp.net repeater databinding, asp.net xpath expressions, c# code, c# tutorials, free source code, download sample code, asp.net youtube api rss, asp.net xmlnamespacemanager addnamespace, xml namespace, rss media namesapce, rss opensearch namespace, asp.net youtube api search, rss feeds
10/11/2008 3:29:40 AM