Search results for Linq to XML - ThinqLinq by ThinqLinq


JSON Literals for VB

One of the stand-out features of VB.Net since VB9 has been the inclusion of XML Literals. Followers of this blog should be well familiar with the concept because I first wrote about XML Literals way back in 2006. With them, we can imbed XML directly into our code as follows:Dim value = <root> <child attrib="foo">bar</child> <root> While XML Literals make the task of working with XML more of a joy than a necessary evil, they do add a cer

Windows 8 Live Tiles and LINQ to XML

When I started working with Windows 8 Metro development, I was disappointed to see that the native WinRT API’s relied on the older XmlDocument and XMLDom rather than the newer subset of XDocument/XElement and LINQ to XML. I suppose this was necessary because the older version was more natural for C++ and JavaScript options for Metro applications. If you’re like me and want to use LINQ to XML to work with XML in WinRT, all you need to do is pass the XML strings back and forth between your C#/VB c

Create an RSS Feed for PDC 2010 videos

I love the fact that Microsoft makes it’s conference materials available for those unfortunate enough not to be able to attend. I also love watching the videos on my Zune. Even better is when I can use the Zune podcasting ability to download these videos. So far, I wasn’t able to find such a feed. Thankfully, fellow MVP, Bill McCarthy posted some quick LINQ to XML code to generate HTML tables based on the Xessions XML that was used for PDC. You can read his post here:

LINQ in Action XML samples added to LINQPad

The beginning of this month, we released the samples from "LINQ in Action" for chapters 1-8 which covers LINQ to Objects, LINQ to SQL, and the new Language features. We're happy to announce that the next three chapters covering LINQ to XML are now available. That's over 70 new samples in VB and C# each. Follow the directions on the original announcement to download and use these samples.

More Ways to create an XML file

Edward Tanguay just posted three comparative examples of creating XML files via String Concatenation, XmlWriter, and LINQ to XML. I would typically respond to a blog post through that site's comments, but public comments are blocked at this point. While his post is a good start and shows pretty easily the simplicity that using LINQ to XML gives over the other options, he does fail to address a couple other options: XmlDocument Serialized objects, and of course XML Literals with VB. Before di

Fetching XML from SQL Server using LINQ to SQL

With SQL Server, you can use the For Xml clause (read more in BOL). The quickest option is to add For XML Auto at the end of a SQL statement. You can do this with dynamic SQL or inside a stored proc. If you use a stored proc, the DBML tool doesn't recognize this as XML (and return it as an XElement as it does for XML Data type columns). Regardless of whether you are using stored procs or dynamic SQL, the server returns the result as an array of strings broken up into 4000 character chunks. It is

Adding a dynamic SiteMap for search engine optimization using LINQ

A couple months ago I added a feature to this site to build a Site Map for this site dynamically based on the information from the database for posts and files for the downloads. If your not familiar with how Sitemap files can help your site searchability, Google has a good documentation about Sitemaps in their Webmaster tools. The SiteMap Protocal is a rather simple XML document consisting of a set of url nodes that consist of the following: loc - URL for the page link lastmod - Date

Screen scraping and creating Word documents with LINQ to XML

At TechEd Developers 2008 in Orlando, I had the pleasure of competing in Speaker Idol. In that competition, we had the opportunity to present a topic in 5 minutes. Unfortunately, the topic I choose really needed 10 minutes to cover at the level of detail it needed. Instead of limiting the topic, I decided to go ahead and present it a bit too fast. If you want to see the video, or see how to use VB 9's XML Literals and LINQ to XML to fetch data from a web page (that must be XHtml compilant), ma

Querying the complete plays of Shakespeare using LINQ to XML

I was working to come up with some creative uses of LINQ to XML for my new talk I'm giving at the Huntsville, AL Code Camp. I figured it would be good to include a sample which queries a large XML document. Remembering that the complete works of Shakespeare were available in XML form, I did a quick search and found a version at This file separates each play out into separate XML files. Since I wanted to find out which parts had the most lines acr

Adding categories to the RSS feed using LINQ to XML

Last time, we added categories to the web view of the ThinqLinq site. This time, we're going to add them to the RSS feed. Because RSS is "Really Simple", adding the categories is fairly easy. According to the RSS specification, <category> is an optional sub-element of <item>. It can additionally contain the domain that contains that category. In our case, we will point the domain to our implementation that displays all posts for a given category by passing the category id to the quer

Adding a RSS feed for file downloads

Ok, so I've been a bit busy this weekend adding some nice stuff for this site. One thing that I wanted to add was another RSS feed, this time for the file upload section. If you want to subscribe to the File RSS feed, direct your aggregator to the following link: Of course, since this is a learning site, I'll let you in on the code needed to accomplish the task. As you may guess, LINQ makes serving up XML from an object collection using a heterogeneous jo

Projecting XML from LINQ to SQL

Among the new cool features in Visual Studio 2008, one of the best may be the XML Literal support with VB 9 and LINQ. In my last post, I mentioned some changing features from the Beta to RTM. One that could easily be overlooked is a change to the way LINQ to SQL can now directly project into XML literals. Through the Beta cycle, there was an issue with projecting XML elements directly from a LINQ to SQL query. If you haven't seen LINQ to SQL with XML, here's a code sample that explains what I'

Creating HTML emails using VB 9 and LINQ

Today, I'm not looking at sending mass spam using LINQ to pull a list of recipients. I'm actually referring to the ability to generate the message body using XML Literals. Using the System.Net.Mail.MailMessage object, we can easily send emails to an SMTP server. The body of the email can either be plain text or HTML. Dynamically generating the text is often a laborious task involving a string builder and lots of method calls. The body corresponds to the body portion of a HTML page. If you use

Using LINQ to query against objects and XML

In preparing for my LINQ talk for DBA's at tomorrow's Atlanta Microsoft Database Forum user group meeting, I thought it would be good to offer a quick look at the LINQ to Objects and LINQ to XML stacks before focusing on the OR mapping portions: LINQ to SQL, LINQ to Entities and LINQ to dataSet. I previously used a quick demo which joined the FileInfo collection returned by DirectoryInfo.GetFiles with an object collection built from a CSV file. For this demo, I wanted to add in the XML stack.

Use LINQ to convert CSV to XML

File conversion is a typical programming task. VB9 should make this task easier to code and maintain as we can eliminate much of the plumbing code and focus on the task at hand. The following example uses the MAY CTP of LINQ and leverages the TextFieldParser added to VB 8 to convert a simple CSV file to XML. For this sample, we will convert a simple CSV file that contains standard windows file extensions with a brief description of the file. Here are the first couple of lines: .doc,Microsoft

Behind LINQ to XML and the Event Log generator

Yesterday, I posted my "cool code" example which extracted information from the event logs and presented them as a RSS document using Linq to XML (XLINQ). At that point, I didn't have time to explain the code. Today, I will deconstruct the code to help explain how it works. As a recap, here's the "one line of code" that handles the task: If EventLog.Exists(LogName) Then _ Response.Write(<channel> <title>Event Log from <%= Environment.MachineName %>&lt

Using LINQ to XML to generate a RSS feed from the event log

The Jacksonville Code Camp tried a new concept which was very well received. In it they asked people to bring "cool code" and show it in 7 minutes. Personally, I'm not sure what can be cooler than VB 9's XML literals, so I decided to give it a shot. In the end, I came up with a ONE LINE solution which can iterate over the event log and generate an XML string in the format of a RSS feed which is served up to the Response stream. When I showed the one line, some were skeptical. Granted,

LINQ to XML Rocks Because

I’m in the process of finalizing a number of presentations on LINQ. I will be posting the demos and slides soon. As a teaser, here’s a quick snippet from the XLinq demo. I begin by showing the new functional construction syntax for XLINQ. 'Uses Functional Construction Dim x As New XElement("LinqEssentials", _ New XElement("Category", "LINQ"), _ New XElement("Category", "DLINQ"), _ New XElement("Category", "XLINQ")) Dim y As New XElement("LanguageFeatures") y.Add(New XElement("release", New XAtt