Episode 11 of Visual Studio Toolbox (Using LINQ to XML to Query Data on the Web) is now live
We have spent the previous 10 episodes looking at extensions. It is time to take a new tack. We are going to explore coding techniques. After all, code is a tool, right?
These days, Web sites are providing access to a large amount of data, everything from RSS feeds to pictures to movie titles and more. Often, all you need to do in an application is send an HTTP request to a Web site. The Web site sends the data back via XML, and the easiest way to work with that data is to use LINQ queries. In this episode, Robert shows you how to use LINQ to XML to make sense of the XML data a Web site sends you. He gives examples of working with an RSS feed, retrieving images from Flickr, querying for wineries and wines using Wine.com, and returning movies from NetFlix. You'll see basic queries, see how to retrieve data from elements and attributes, and see how to work with namespaces.
You can find this episode at https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-Toolbox-Using-LINQ-to-XML-to-Query-Data-on-the-Web or watch it here. And, as promised, the code I used is attached for your viewing and coding pleasure.
Comments
Anonymous
September 29, 2011
Good one. It is practical. By the way, I want to sign in before comment but the site gave me error.Anonymous
September 29, 2011
Hi Robert, Thanks for this post, it's really useful. I think it could be even better if you'd added a XML creation stuff here, and not in your next post (as you promised). The reason behind this is that many web services use XML-encoded, and not URL-encoded parameters to specify the request's details. I'll wait for your post about creation of XML with LINQ, anyway.Anonymous
September 30, 2011
I appreciate all your sessions on Channel 9. They are very helpful. It is also very useful that you show the coding in C# and VB.NET. Thanks and see you in the next session ... KlausAnonymous
October 08, 2011
Thank you for the great Video Robert. How would I handle recursion of elements in the xml tree or depth feature in the decendents method. <itemA> . <itemA> .... <itemA> ... </itemA>... </itemA> .... </itemA> </itemA> Thanks.Anonymous
December 20, 2011
I like this style of deep dive, but I have one remark. Never use the query operator Count() to check for the presence of items in a sequence! You should generally use Any(), as Count() needs to read the complete sequence. (In your example prefer !posts.Any() over posts.Count() == 0; because you are materializing the sequence twice, in Count() and on iterating the sequence.)