Typed XML programmer -- Welcome to LINQ!

Typed XML programmer -- Welcome to LINQ!

  • Comments 40

Announcing the LINQ to XSD Preview

 

Ever since PDC 2005, when XLinq was unleashed (now called LINQ to XML), we have been receiving questions about the possibility of a typed XML programming approach in the LINQ world. Not surprisingly, we have been pondering about this problem indeed. This was also mentioned in the XLinq overview. (Please, also see the “Typed XML programmer” series of blog posts.) For some time now we have been focusing incubation efforts on typed XML programming for LINQ. One overall approach is to engage in a mapping of XML types to ‘plain’ object types, that is, classes with ‘fields that maintain state’ and with support for XML serialization and de-serialization. While this approach would effectively reduce typed XML programming to ‘LINQ to objects’ + de-/serialization, it potentially leads to a lossy and complicated XML programming model. Consequently, our efforts have focused on a more natural and faithful approach which builds on top of LINQ to XML.

 

Today we are happy to announce the LINQ to XSD Preview Alpha 0.1:

 

 

We'd like to encourage everyone with a stake in XML programming and ‘schema-first’ applications to take a look at LINQ to XSD and send your observations, questions and suggestions this way; we'll be eagerly waiting for feedback! The whole point of this incubation project is to investigate options for the future of typed XML programming. We are still very early in the design process. So your feedback is critical and can help shape the design of the project as we are going forward.

 

This is pre-release software; it is provided “as-is” – we’re crucially interested in getting feedback from customers but we can’t make any guarantee with regard to supporting or maintaining this software or releasing future versions on any specific timeline. In particular, while the underlying LINQ to XML technology is expected for Orcas, no such commitment exists for LINQ to XSD.

 

 

What is LINQ to XSD?

 

LINQ to XSD provides .NET developers with support for typed XML programming on top of LINQ to XML. While the LINQ to XML programmer operates on generic XML trees, the LINQ to XSD programmer operates on typed XML trees -- instances of .NET types that model the XML types of a specific XML schema (XSD). To get an idea, consider the following C#3.0 fragment for a LINQ to XML query that computes the total over the items in a XML tree for a purchase order:

 

     (from item in purchaseOrder.Elements("Item")

      select (double)item.Element("Price")

           * (int)item.Element("Quantity")

     ).Sum();

 

Using LINQ to XSD, the query is written in a much clearer and type-safe way:

 

     (from item in purchaseOrder.Item

      select item.Price * item.Quantity

     ).Sum();

 

LINQ to XSD can be used whenever you have an XML schema available, or you are willing to infer a schema from the XML data at hand. LINQ to XSD is integrated into Visual Studio; so you just tag an XML schema as an ‘LINQ to XSD schema’, build your project, and the automatically derived object model is then part of your solution -- just as if XML schemas were .NET types.

 

The derived object model enforces various validation constraints imposed by the underlying XML schema -- quite similar to other technologies for so-called X/O mapping or XML data binding. Two important aspects of LINQ to XSD are its integration into the LINQ family of technologies and its foundation on ‘XML objects’ as opposed to ‘plain objects’. That is, the derived object models provide XML semantics in terms of XML fidelity and programming idioms. To this end, the derived object models define .NET types (classes) that are essentially views on generic LINQ to XML trees. Typed member access and other typed axes can be used in most cases, while untyped tree access is still available, when necessary.

 

 

What’s in the release?

 

  • An overview document -- also available separately.
  • A mapping tool deriving object models from XML schemas.
  • Visual Studio templates for C# LINQ to XSD projects.
  • A command-line interface for the abovementioned tool.
  • Samples (scenario-based and API-based).
  • A technical user manual.
  • A mapping documentation.

 

 

LINQ to XSD-related pointers

 

 

 

We really look forward receiving your feedback.

 

Ralf Lämmel

Data Programmability / XML team

  • PingBack from http://blogs.msdn.com/ralflammel/archive/2006/11/13/table-of-contents-for-typed-xml-programmer-series.aspx

  • Woo hoo!  I wondered when y'all were going to post this.  :)

  • A month ago I was investigating authoring WF rules against XML. We dont support it out of the box, but

  • Voici un nouveau venu dans la famille " Linq To .... " qui risque de plaire à pas mal de développeurs

  • After working sometime with LINQ this becomes quite a missing feature. This will make my life way easier

  • I was waiting for this! :)

  • Not to be ungrateful, but I'm a little disappointed that "typed" XML programming is only putting a typed wrapper around raw XML. I'm not quite satisfied with setters and getters on numeric properties having to format and parse strings every time. What I really want is XML objects that store the data according to the XSD type and when using XmlReader and XmlWriter call the appropriate strongly-typed methods, so strongly-typed data can be copied from one XML object to another via XmlReader or XmlWriter without formatting, parsing, or even boxing.

  • Workflow/BPM/WCF/SOA David Chappell presents arguments both pro and con as to whether Microsoft qualifies

  • Hi MKane91301,

    thanks for your reflection. When you say that you are a little disappointed because typed XML programming is *only* [my emphasis] putting a typed wrapper around raw XML, then you seem to focus on *performance*, which is important, but it is not the only dimension we need to keep an eye on. The wrapper approach has the distinguished advantage of reusing existing LINQ to XML objects, as is, and keeping them in tact. This is an extremely valuable feature in a setting where we assume that people mostly use LINQ (LINQ to XML) and occasionally (hopefully often) want to create typed views w/o disturbing the application context of these XML trees. One can try to use caching to get the best of both worlds. However, this is a sort of wormhole I should blog about in all detail some day.

    Also, a big problem, IMHO, with the approach that stores *parts* of trees or just values in plain fields (as you seem to ponder about) is that this leads eventually to the lossiness and complexity of serialization approaches.

    Your feedback is very appreciated.

    Thanks,

    Ralf Laemmel

  • why generated classes are not partial ?

    (or they are but in l2xsd_overview.doc they are not in exapmle ;p)

  • Hi rad9k,

    sure the generated classes are partial (and public). The pseudo code in the overview doc favored to elide these modifiers, but this may be debatable as I sense from your email.

    Thanks,

    Ralf

  • Now that I kicked off LINQ to XSD (a piece of XMLware), it’s time to rest and think about IT and entropy

  • Microsoft XML Team's WebLog : Typed XML programmer -- Welcome to LINQ! Download details LINQ to XSD LINQ를

  • How is Linq-to-XSD different from generating classes via xsd.exe, loading these typed objects into memory via XmlSerializer, and then running plain Linq on in-memory objects?

    Thanks - George

Page 1 of 3 (40 items) 123