LINQ in Action - LINQ Book & News

LINQ to XSD - Typed XML programming with LINQ

I haven't written about LINQ to XSD yet on this blog. So, here goes...

LINQ to XML has been revealed with the first versions of LINQ. It was known as XLinq at that time. LINQ to XML allows querying and creating XML trees and documents. The limitation is that it works on generic XML. You deal with elements and attributes, but not in a strongly-typed way.

LINQ to XSD has been created to improve this. It allows typed XML programming on top of LINQ to XML.
LINQ to XSD, as you would expect, requires an XML Schema (XSD). This schema is used to generate an object model that can then be used to manipulate XML data through LINQ, while enforcing types and the various validation constraints specified in the XML schema.

To show you how LINQ to XSD makes the query syntax much safer and cleaner, let's look at a simple example.
Here is a LINQ to XML query:

from item in purchaseOrder.Elements("Item")
select (double)item.Element("Price") * (int)item.Element("Quantity")

Here is the same query as above, but written using LINQ to XSD:

from item in purchaseOrder.Item
select item.Price * item.Quantity

LINQ to XSD's benefits compared to LINQ to XML include:

  • Improved readability
  • Type-checking at compile time
  • IntelliSense support (completion)

You can get the details on the announcement post by Microsoft's XML team.
As Steve points out, Ralf Lämmel - who is working on LINQ to XSD - has papers on the subject if you want to learn more.

Published Monday, January 15, 2007 7:45 PM by admin

Comments

 

AlexanderZeitler said:

Do you have more details on the current state of LINQ to XSD? Will it be in the Final Release of .NET 3.5?

November 17, 2007 1:39 PM
 

Fabrice Marguerie said:

No news about LINQ to XSD at this point. It's not in the final release of .NET 3.5, which is now available.

Hopefully, we'll learn more about the future of LINQ to XSD in the official LINQ forum. See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2422933&SiteID=1

November 19, 2007 6:26 AM
 

Alex said:

Thanks for the link.

November 23, 2007 6:15 AM
New Comments to this post are disabled