Fremus.co.za

Demistifying Life and Web Development

Archive for the 'Bing' Category

Getting search results from Bing REST service and using LINQ to process results

So today I started reading about the Bing API and I got myself an API key and I read through the basic instruction manual, which tells you how to get search results from the web through the Bing REST service. Its pretty straight forward, just get your own key though! But here is some sample code that does the trick and uses Linq to XML to process the results:

            XDocument document = XDocument.Load("http://api.search.live.net/xml.aspx?Appid=&query=sushi&sources=web");
            XElement root = document.Root;
            XNamespace web = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web";
            var searchItems = document.Descendants(web + "Results").SingleOrDefault();

            IEnumerable testelem = from el in searchItems.Elements()
                                                 select el;
            foreach (XElement myElem in testelem)
            {
                context.Response.Write(myElem.Value + "");
            }

That is very easy!

  • Share/Bookmark
posted by fr3dr1k in Bing,C#,LINQ to XML and have No Comments
Get Adobe Flash playerPlugin by wpburn.com wordpress themes